Changeset 1409

Show
Ignore:
Timestamp:
07/26/09 12:25:29 (3 years ago)
Author:
networkfusion
Message:

* Addded New Geocoders Yahoo and Google.
* Geocoder now defaults to google if no country specific
Geocoder is found (in future, this will be made selectable by network)
* Fixed Postcode search on Find Hotspot Map #436
* Added search for user by email closes #417
* Added validation to networkID to stop database errors, closes
#458

Location:
trunk/wifidog-auth
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r1403 r1409  
    11# $Id$ 
     2 
     32009-07-26 Robin Jones 
     4        * Addded New Geocoders Yahoo and Google. 
     5        * Geocoder now defaults to google if no country specific Geocoder is found (in future, this will be made selectable by network) 
     6        * Fixed Postcode search on Find Hotspot Map #436 
     7        * Added search for user by email closes #417 
     8        * Added validation to networkID to stop database errors, closes #458 
     9         
    210 
    3112009-07-10 Benoit Grégoire <benoitg@coeus.ca> 
  • trunk/wifidog-auth/wifidog/classes/AbstractGeocoder.php

    r1013 r1409  
    6868    // Implementation attributes 
    6969    private $endpoint_url; 
     70    private $APIKey; 
    7071    // This value is only used to prevent from running to same query twice 
    7172    private $execute_query = true; 
    7273 
    7374    // Factory method hash map 
    74     private static $implementations_map = array ("Canada" => "GeocoderCanada", "USA" => "GeocoderUsa"); 
     75    private static $implementations_map = array ("Canada" => "GeocoderCanada", "USA" => "GeocoderUsa", "UK" => "GeocoderYahooGlobal", "Earth" => "GeocoderGoogleGlobal"); 
    7576 
    7677    /** Returns a list of countries for which we provide a geocoder implementation 
     
    205206        $this->execute_query = false; 
    206207    } 
     208 
     209    protected function setAPIKey($APIKey) 
     210    { 
     211        $this->APIKey = $APIKey; 
     212    } 
     213 
     214    public function getAPIKey() 
     215    { 
     216        return $this->APIKey; 
     217    } 
     218 
    207219 
    208220    abstract public function validateAddress(); 
  • trunk/wifidog-auth/wifidog/classes/Network.php

    r1401 r1409  
    329329        $name = "new_network_id"; 
    330330        $html .= "<input type='text' size='10' name='{$name}'>\n"; 
    331  
    332331        return $html; 
    333332    } 
     
    352351        if (!empty($_REQUEST[$name])) { 
    353352            $network_id = $_REQUEST[$name]; 
     353 
     354            if (!preg_match('/^[0-9a-zA-Z_-]+$/', $network_id)) { 
     355            throw new Exception(_("The Network ID entered was not valid. It must only contain Alphanumerical Characters, Hyphens and Underscores e.g. My_Network-6")); 
     356            return; 
     357            } 
    354358 
    355359            if ($network_id) { 
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r1393 r1409  
    14771477        if (!empty ($_REQUEST['geocode_only'])) 
    14781478        { 
    1479             $geocoder = AbstractGeocoder :: getGeocoder($this->getCountry()); 
     1479            if ($geocoder = AbstractGeocoder :: getGeocoder($this->getCountry()) != null) 
     1480                $geocoder = AbstractGeocoder :: getGeocoder($this->getCountry());           
     1481            else 
     1482                $geocoder = AbstractGeocoder :: getGeocoder('Earth'); 
     1483 
    14801484            if ($geocoder != null) 
    14811485            { 
     
    14851489                $geocoder->setProvince($this->getProvince()); 
    14861490                $geocoder->setPostalCode($this->getPostalCode()); 
    1487                 if ($geocoder->validateAddress() === true) 
     1491                if ($geocoder->validateAddress() == true) 
    14881492                { 
    14891493                    if (($point = $geocoder->getGisLocation()) !== null) 
  • trunk/wifidog-auth/wifidog/classes/User.php

    r1406 r1409  
    173173 
    174174    /** Instantiate a user object 
     175     * @param $usernameOrEmail The username or the email address of the user 
     176     * @param &$errMsg An error message will be appended to this if the username is not empty, but the user doesn't exist. 
     177     * @return a User object, or null if there was an error 
     178     */ 
     179    public static function getUserByUsernameOrEmail($usernameOrEmail, &$errMsg = null) { 
     180        $db = AbstractDb::getObject(); 
     181        $object = null; 
     182 
     183        $usernameOrEmail_str = $db->escapeString($usernameOrEmail); 
     184        $db->execSqlUniqueRes("SELECT user_id FROM users WHERE username ILike '$usernameOrEmail_str' OR email ILike '$usernameOrEmail_str'", $user_info, false); 
     185 
     186        if ($user_info != null) { 
     187            $object = self::getObject($user_info['user_id']); 
     188        } 
     189        else if (!empty($usernameOrEmail)) { 
     190            $errMsg .= sprintf(_("There is no user with username or email %s"),$usernameOrEmail); 
     191        } 
     192        return $object; 
     193    } 
     194  
     195 
     196   /** Instantiate a user object 
    175197     * @param $url The OpenId url 
    176198     * @return a User object, or null if none matched 
     
    813835            $userSelector .= InterfaceElements :: generateInputSubmit($add_button_name, $add_button_value); 
    814836        } else { 
    815             $userSelector = _("Username") . ": " . InterfaceElements :: generateInputText("select_user_" . $user_prefix . "_username"); 
    816         } 
    817         $html = "<div class='user_select_user_ui_container'>".$networkSelector . $userSelector . "</div>\n"; 
     837            $userSelector = _("Search for Username or Email Address") . ": " . InterfaceElements :: generateInputText("select_user_" . $user_prefix . "_username"); 
     838        } 
     839        $html = "<div class='user_select_user_ui_container'>".$networkSelector . "<br>" . $userSelector . "</div>\n"; 
    818840        return $html; 
    819841    } 
     
    831853            if (!empty ($_REQUEST[$name])) { 
    832854                $username = $_REQUEST[$name]; 
    833                 return self :: getUserByUsernameAndOrigin($username, $network, $errMsg); 
     855                return self :: getUserByUsernameOrEmail($username, $errMsg); 
    834856            } else 
    835857            return null; 
     
    865887            $name = "user_" . $this->getId() . "_username"; 
    866888            $content = "<input type='text' name='$name' value='" . htmlentities($this->getUsername()) . "' size=30><br/>\n"; 
    867             $content .= _("Be carefull when changing this: it's the username you use to log in!"); 
     889            $content .= _("Be careful when changing this: it's the username you use to log in!"); 
    868890            $userPreferencesItems[] = InterfaceElements::genSectionItem($content, $title); 
     891 
     892 
     893            /* Email */ 
     894            $title = _("Email"); 
     895            $name = "email_" . $this->getId() . "_email"; 
     896            $content = "<input type='text' name='$name' disabled='disabled' value='" . htmlentities($this->getEmail()) . "' size=30><br/>\n"; 
     897            $content .= _("If you wish to change this address, please Email Support!"); 
     898            $userPreferencesItems[] = InterfaceElements::genSectionItem($content, $title); 
     899 
     900 
    869901 
    870902            /* Change password */ 
  • trunk/wifidog-auth/wifidog/geocoder.php

    r916 r1409  
    5555if(!empty($_REQUEST["postal_code"])) 
    5656{ 
    57     $geocoder = AbstractGeocoder::getGeocoder("Canada"); 
     57    $geocoder = AbstractGeocoder::getGeocoder("Earth"); 
    5858    $geocoder->setPostalCode($_REQUEST["postal_code"]); 
    5959    $long = $geocoder->getLongitude(); 
  • trunk/wifidog-auth/wifidog/js/hotspots_status_map.js

    r1066 r1409  
    4242 */ 
    4343 
     44// Create a Global array that will contain refs to markers 
     45var markers = new Array(); 
     46 
    4447// Translations 
    4548function HotspotsMapTranslations(browser_support, homepage, show_on_map, loading) 
     
    6467 
    6568        // Create the array that will contain refs to markers 
    66         this.markers = Array(); 
     69        //markers = Array(); 
    6770 
    6871        // Init source url 
     
    8588    var self = this; 
    8689    GDownloadUrl("geocoder.php?postal_code=" + postal_code, function(data, responseCode) { 
    87             var root_node = GXml.parse(data).documentElement 
     90        // To ensure against HTTP errors that result in null or bad data, 
     91        // always check status code is equal to 200 before processing the data 
     92        if(responseCode == 200) { 
     93                var root_node = GXml.parse(data).documentElement 
    8894                self.findClosestHotspotByCoords(new GLatLng(GXml.value(root_node.getElementsByTagName("lat")[0]), GXml.value(root_node.getElementsByTagName("long")[0]))); 
     95        }else if(responseCode == -1) { 
     96    alert("Data request timed out. Please try later."); 
     97  } else {  
     98    alert("Request resulted in error. Check XML file is retrievable."); 
     99  } 
     100 
    89101        }); 
    90102} 
    91103 
     104 
    92105HotspotsMap.prototype.findClosestHotspotByPostalCode = function(postal_code) 
    93106{ 
    94     if (postal_code != undefined && this.markers.length > 0) { 
     107    if (postal_code != undefined && markers.length > 0) { 
    95108        this.getGPointFromPostalCode(postal_code); 
    96109    } 
     
    99112HotspotsMap.prototype.findClosestHotspotByCoords = function(coord) 
    100113{ 
    101     if (coord != null && this.markers.length > 0) { 
     114    if (coord != null && markers.length > 0) { 
    102115        // Init values 
    103116        var dist = null; 
     
    105118 
    106119        // For each registered markers 
    107         for(i in this.markers) { 
    108                    if(this.markers[i] && this.markers[i].getPoint) { 
     120        for(i in markers) { 
     121                   if(markers[i] && markers[i].getPoint) { 
    109122                    // Compute the distance in meters between the two points 
    110                     tmp = coord.distanceFrom( this.markers[i].getPoint()); 
    111  
     123                    tmp = coord.distanceFrom( markers[i].getPoint()); 
    112124                    if(dist == null || tmp < dist) { 
    113125                        dist = tmp 
     
    261273{ 
    262274    // Trigger click ( NB. markers is a global var ) 
    263     GEvent.trigger(this.markers[bubbleId], "click"); 
     275    GEvent.trigger(markers[bubbleId], "click"); 
    264276} 
    265277 
     
    335347            // Prepare fragment that will go in the sidebar 
    336348            var html = this.buildHtmlFromHotspot(hotspots[i], markerIcon); 
    337             html_list += html + "<br /><br /><a href=\"javascript:" + this.external_object_name +".openInfoBubble('" + GXml.value(hotspotId[0]) + "');\">" + this.translations.show_on_map + "</a><hr width='95%'/>"; 
     349            html_list += html + "<br /><br /><a href=\"javascript:" + this.external_object_name +".openInfoBubble('" + markers.length + "');\">" + this.translations.show_on_map + "</a><hr width='95%'/>"; 
    338350 
    339351            // Create, save as ID and add the marker 
     
    341353 
    342354            // markers is a global var 
    343             this.markers[GXml.value(hotspotId[0])] = marker; 
     355            //markers[GXml.value(hotspotId[0])] = marker; 
     356            markers[markers.length] = marker; 
    344357            this.map.addOverlay(marker); 
    345358        } 
     
    352365HotspotsMap.prototype.redraw = function() 
    353366{ 
    354     for (i = 0;i < this.markers.length;i++) { 
    355         this.map.removeOverlay(this.markers[i]); 
     367    for (i = 0;i < markers.length;i++) { 
     368        this.map.removeOverlay(markers[i]); 
    356369    } 
    357370 
  • trunk/wifidog-auth/wifidog/templates/sites/hotspots_map.tpl

    r1249 r1409  
    6262                {"Enter your postal code"|_}:<br/> 
    6363                <input type="text" id="postal_code" size="10"><p/> 
    64                 <input type="button" value="{"Show"|_}" onclick="toggleOverlay('map_postalcode_overlay'); p = document.getElementById('postal_code'); hotspots_map.findClosestHotspotByPostalCode(p.value);"> 
     64                <input type="button" value="{"Show"|_}" onclick="toggleOverlay('map_postalcode_overlay'); p = document.getElementById('postal_code'); HotspotsMap.prototype.findClosestHotspotByPostalCode(p.value);"> 
    6565            </div> 
    6666