<commit_before><?php
/*"******************************************************************************************************
 *   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
 *   (c) 2007-2009 by Kajona, www.kajona.de                                                              *
 *       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
 *-------------------------------------------------------------------------------------------------------*
 *   $Id$                                      *
 ********************************************************************************************************/


/**
 * Class to receive geo coordinates of local addresses using external services like Google Maps.
 * Please set your API hosts and keys in the service-specific function, e.g. lookupAddressUsingGoogle()
 * Choose which remote service you want to use by setting the ApiId like:
 *     $objGeocoder = new class_geocoder(0);    (0 = Google Maps; 1 = Yahoo! Maps)
 * ATTENTION: Please respect the terms of use of the remote services! E.g. Google only allows the use
 * in conjunction with displaying the results on a Google map.
 *
 * @author jschroeter
 * @package element_maps
 */
class class_geocoder {
    /**
     * 0 = Google Maps
     * 1 = Yahoo! Maps
     *
     * @var int
     */
    private $intApiId = 1;

    private $strResponseRaw = "";
    private $strStreet = "";
    private $strPostalCode = "";
    private $strCity = "";
    private $strAdministrativeArea = "";
    private $strSubAdministrativeArea = "";
    private $strCountryCode = "";
    private $floatLatitude = 0.0;
    private $floatLongitude = 0.0;
    private $intAccuracy = 0;

    /**
     * Constructor
     *
     * @param int $intApiId
     */
    public function __construct($intApiId = 0) {
        $this->intApiId = $intApiId;
    }

    /**
     * Does the remote address lookup.
     * Returns true if an address was found. Keep in mind that it could be an wrong address,
     * so in some cases it makes sense to compare e.g the requested with the received postal
     * code or country code.
     *
     * @param string $strStreet
     * @param string $strPostalCode
     * @param string $strCity
     * @param string $strCountry
     *
     * @return bool
     */
    public function lookupAddress($strStreet = "", $strPostalCode = "", $strCity = "", $strCountry = "") {
        $bitReturn = false;

        $this->strResponseRaw = "";
        $this->strStreet = "";
        $this->strPostalCode = "";
        $this->strCity = "";
        $this->strCountryCode = "";
        $this->floatLatitude = 0.0;
        $this->floatLongitude = 0.0;
        $this->intAccuracy = 0;

        if($this->intApiId == 0) {
            $bitReturn = $this->lookupAddressUsingGoogle($strStreet, $strPostalCode, $strCity, $strCountry);
        }
        else if($this->intApiId == 1) {
            $bitReturn = $this->lookupAddressUsingYahoo($strStreet, $strPostalCode, $strCity, $strCountry);
        }

        return $bitReturn;
    }

    /**
     * Does the remote address lookup using the Google Maps API. Returns true if an address was found.
     * For further information please refer to http://code.google.com/apis/maps/documentation/geocoding/index.html
     *
     * @param string $strStreet
     * @param string $strPostalCode
     * @param string $strCity
     * @param string $strCountry
     *
     * @return bool
     */
    private function lookupAddressUsingGoogle($strStreet = "", $strPostalCode = "", $strCity = "", $strCountry = "") {
        $bitReturn = false;

        $strHost = "maps.google.de"; //change this to your country/language e.g. maps.google.it
        $strApiKey = ""; //change this; probably not needed anymore
        $strQuery = "/maps/geo?output=xml"."&key=".$strApiKey."&sensor=false&oe=utf8&q=".urlencode($strStreet.", ".$strPostalCode." ".$strCity.", ".$strCountry);

        $objRemoteloader = new class_remoteloader();
        $objRemoteloader->setStrHost($strHost);
        $objRemoteloader->setStrQueryParams($strQuery);


        //send another delayed requests if requests were sent too fast
        $intDelay = 0;
        $bitResponsePending = true;
        while($bitResponsePending) {
            try {
                $bitForceReload = $intDelay > 0 ? true : false;
                $strResponse = $objRemoteloader->getRemoteContent($bitForceReload);
            }
            catch(class_exception $objExeption) {
                $bitResponsePending = false;
                $bitReturn = false;
                $strResponse = false;
            }

            if($strResponse != false) {
                $this->strResponseRaw = $strResponse;
<commit_msg>added missing phpdoc<commit_after><?php
/*"******************************************************************************************************
 *   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
 *   (c) 2007-2009 by Kajona, www.kajona.de                                                              *
 *       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
 *-------------------------------------------------------------------------------------------------------*
 *   $Id$                                      *
 ********************************************************************************************************/


/**
 * Class to receive geo coordinates of local addresses using external services like Google Maps.
 * Please set your API hosts and keys in the service-specific function, e.g. lookupAddressUsingGoogle()
 * Choose which remote service you want to use by setting the ApiId like:
 *     $objGeocoder = new class_geocoder(0);    (0 = Google Maps; 1 = Yahoo! Maps)
 * ATTENTION: Please respect the terms of use of the remote services! E.g. Google only allows the use
 * in conjunction with displaying the results on a Google map.
 *
 * @author jschroeter
 * @package element_maps
 */
class class_geocoder {
    /**
     * 0 = Google Maps
     * 1 = Yahoo! Maps
     *
     * @var int
     */
    private $intApiId = 1;

    private $strResponseRaw = "";
    private $strStreet = "";
    private $strPostalCode = "";
    private $strCity = "";
    private $strAdministrativeArea = "";
    private $strSubAdministrativeArea = "";
    private $strCountryCode = "";
    private $floatLatitude = 0.0;
    private $floatLongitude = 0.0;
    private $intAccuracy = 0;

    /**
     * Constructor
     *
     * @param int $intApiId
     */
    public function __construct($intApiId = 0) {
        $this->intApiId = $intApiId;
    }

    /**
     * Does the remote address lookup.
     * Returns true if an address was found. Keep in mind that it could be an wrong address,
     * so in some cases it makes sense to compare e.g the requested with the received postal
     * code or country code.
     *
     * @param string $strStreet
     * @param string $strPostalCode
     * @param string $strCity
     * @param string $strCountry
     *
     * @return bool
     */
    public function lookupAddress($strStreet = "", $strPostalCode = "", $strCity = "", $strCountry = "") {
        $bitReturn = false;

        $this->strResponseRaw = "";
        $this->strStreet = "";
        $this->strPostalCode = "";
        $this->strCity = "";
        $this->strCountryCode = "";
        $this->floatLatitude = 0.0;
        $this->floatLongitude = 0.0;
        $this->intAccuracy = 0;

        if($this->intApiId == 0) {
            $bitReturn = $this->lookupAddressUsingGoogle($strStreet, $strPostalCode, $strCity, $strCountry);
        }
        else if($this->intApiId == 1) {
            $bitReturn = $this->lookupAddressUsingYahoo($strStreet, $strPostalCode, $strCity, $strCountry);
        }

        return $bitReturn;
    }

    /**
     * Does the remote address lookup using the Google Maps API. Returns true if an address was found.
     * For further information please refer to http://code.google.com/apis/maps/documentation/geocoding/index.html
     *
     * @param string $strStreet
     * @param string $strPostalCode
     * @param string $strCity
     * @param string $strCountry
     *
     * @return bool
     */
    private function lookupAddressUsingGoogle($strStreet = "", $strPostalCode = "", $strCity = "", $strCountry = "") {
        $bitReturn = false;

        $strHost = "maps.google.de"; //change this to your country/language e.g. maps.google.it
        $strApiKey = ""; //change this; probably not needed anymore
        $strQuery = "/maps/geo?output=xml"."&key=".$strApiKey."&sensor=false&oe=utf8&q=".urlencode($strStreet.", ".$strPostalCode." ".$strCity.", ".$strCountry);

        $objRemoteloader = new class_remoteloader();
        $objRemoteloader->setStrHost($strHost);
        $objRemoteloader->setStrQueryParams($strQuery);


        //send another delayed requests if requests were sent too fast
        $intDelay = 0;
        $bitResponsePending = true;
        while($bitResponsePending) {
            try {
                $bitForceReload = $intDelay > 0 ? true : false;
                $strResponse = $objRemoteloader->getRemoteContent($bitForceReload);
            }
            catch(class_exception $objExeption) {
                $bitResponsePending = false;
                $bitReturn = false;
                $strResponse = false;
            }

            if($strResponse != false) {
                $this->strResponseRaw = $strResponse;

                /** @var SimpleXMLElement $xml */
{'fraction_non_alphanumeric': 0.1735931184578713, 'fraction_numerical': 0.008291014612913256, 'mean_word_length': 2.1088917525773194, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6525127', 'n_tokens_mistral': 2734, 'n_tokens_neox': 2550, 'n_words': 695}