Get address string

@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since  2012-04-25

@param  bool  $include_country

@return string
495309
public function getAddress($include_country = false)
    {
        $string = '';
        if ($v = $this->getAddressLine1()) $string .= $v.', ';
        if ($v = $this->getAddressLine2()) $string .= $v.', ';
        if ($v = $this->getAddressLine3()) $string .= $v.', ';
        $string .= $this->getCityStateZip();

        if ($include_country) $string .= $this->getCountryCode();

        return $string;
    }
435053
function addAddressBookEntry($customer_id, $address_question_arr, $make_default = false) {
    global $db;

    // debug
    $this->zcLog('addAddressBookEntry - 1', 'address to add: ' . "\n" . print_r($address_question_arr, true));

    // if address is blank, don't do any matching
    if ($address_question_arr['street_address'] == '') return false;

    // set some defaults
    $country_id = '223';
    $address_format_id = 2; //2 is the American format

    // first get the zone id's from the 2 digit iso codes
    // country first
    $sql = "SELECT countries_id, address_format_id
                FROM " . TABLE_COUNTRIES . "
                WHERE countries_iso_code_2 = :countryCode:
                OR countries_name = :countryName:
                OR countries_iso_code_2 = :countryName:
                OR countries_name = :countryCode:
                LIMIT 1";
    $sql = $db->bindVars($sql, ':countryCode:', $address_question_arr['country']['iso_code_2'], 'string');
    $sql = $db->bindVars($sql, ':countryName:', $address_question_arr['country']['title'], 'string');
    $country = $db->Execute($sql);

    // see if we found a record, if not default to American format
    if (!$country->EOF) {
      $country_id = $country->fields['countries_id'];
      $address_format_id = (int)$country->fields['address_format_id'];
    } else {
      // if defaulting to US, make sure US is valid
      $sql = "SELECT countries_id FROM " . TABLE_COUNTRIES . " WHERE countries_id = :countryId LIMIT 1";
      $sql = $db->bindVars($sql, ':countryId', $country_id, 'integer');
      $result = $db->Execute($sql);
      if ($result->EOF) {
        $this->notify('NOTIFY_HEADER_ADDRESS_BOOK_ADD_ENTRY_INVALID_ATTEMPT');
        $this->zcLog('addAddressBookEntry - 3', 'Failed to add address due to country restrictions');
        return FALSE;
      }
    }

    // see if the country code has a state
    $sql = "SELECT zone_id
                FROM " . TABLE_ZONES . "
                WHERE zone_country_id = :zoneId
                LIMIT 1";
    $sql = $db->bindVars($sql, ':zoneId', $country_id, 'integer');
    $country_zone_check = $db->Execute($sql);
    $check_zone = $country_zone_check->RecordCount();

    // now try and find the zone_id (state/province code)
    // use the country id above
    if ($check_zone) {
      $sql = "SELECT zone_id
                    FROM " . TABLE_ZONES . "
                    WHERE zone_country_id = :zoneId
                    AND (zone_code = :zoneCode
                    OR zone_name = :zoneCode )
                    LIMIT 1";
      $sql = $db->bindVars($sql, ':zoneId', $country_id, 'integer');
      $sql = $db->bindVars($sql, ':zoneCode', $address_question_arr['state'], 'string');
      $zone = $db->Execute($sql);
      if (!$zone->EOF) {
        // grab the id
        $zone_id = $zone->fields['zone_id'];
      } else {
        $zone_id = 0;
      }
    }

    // now run the insert

    // this isn't the best way to get fname/lname but it will get the majority of cases
    list($fname, $lname) = explode(' ', $address_question_arr['name']);

    $sql_data_array= array(array('fieldName'=>'entry_firstname', 'value'=>$fname, 'type'=>'string'),
                           array('fieldName'=>'entry_lastname', 'value'=>$lname, 'type'=>'string'),
                           array('fieldName'=>'entry_street_address', 'value'=>$address_question_arr['street_address'], 'type'=>'string'),
                           array('fieldName'=>'entry_postcode', 'value'=>$address_question_arr['postcode'], 'type'=>'string'),
                           array('fieldName'=>'entry_city', 'value'=>$address_question_arr['city'], 'type'=>'string'),
                           array('fieldName'=>'entry_country_id', 'value'=>$country_id, 'type'=>'integer'));
    if ($address_question_arr['company'] != '' && $address_question_arr['company'] != $address_question_arr['name']) array('fieldName'=>'entry_company', 'value'=>$address_question_arr['company'], 'type'=>'string');
    $sql_data_array[] = array('fieldName'=>'entry_gender', 'value'=>$address_question_arr['payer_gender'], 'type'=>'enum:m|f');
    $sql_data_array[] = array('fieldName'=>'entry_suburb', 'value'=>$address_question_arr['suburb'], 'type'=>'string');
    if ($zone_id > 0) {
      $sql_data_array[] = array('fieldName'=>'entry_zone_id', 'value'=>$zone_id, 'type'=>'integer');
      $sql_data_array[] = array('fieldName'=>'entry_state', 'value'=>'', 'type'=>'string');
    } else {
      $sql_data_array[] = array('fieldName'=>'entry_zone_id', 'value'=>'0', 'type'=>'integer');
      $sql_data_array[] = array('fieldName'=>'entry_state', 'value'=>$address_question_arr['state'], 'type'=>'string');
    }
    $sql_data_array[] = array('fieldName'=>'customers_id', 'value'=>$customer_id, 'type'=>'integer');
    $db->perform(TABLE_ADDRESS_BOOK, $sql_data_array);

    $new_address_book_id = $db->Insert_ID();

    $this->notify('NOTIFY_HEADER_ADDRESS_BOOK_ADD_ENTRY_DONE');

    // make default if set, update
    if ($make_default) {
      $sql_data_array = array();
      $sql_data_array[] = array('fieldName'=>'customers_default_address_id', 'value'=>$new_address_book_id, 'type'=>'integer');
      $where_clause = "customers_id = :customersID";
      $where_clause = $db->bindVars($where_clause, ':customersID', $customer_id, 'integer');
      $db->perform(TABLE_CUSTOMERS, $sql_data_array, 'update', $where_clause);
      $_SESSION['customer_default_address_id'] = $new_address_book_id;
    }

    // set the sendto
    $_SESSION['sendto'] = $new_address_book_id;

    // debug
    $this->zcLog('addAddressBookEntry - 2', 'added address #' . $new_address_book_id. "\n" . 'SESSION[sendto] is now set to ' . $_SESSION['sendto']);

    // return the address_id
    return $new_address_book_id;
  }
310064
public static function getPhoneCodeCountry($code, $show_country_code = false)
    {
        $listPhoneCodes = self::phoneCodesList();
        $country = $listPhoneCodes[$code];

        if ($show_country_code) {
            $country = self::getCountry($country);
        }

        return $country;
    }
529014
public function _get($condition = "1=1", $include = false, $useCache = false) {
		try {
			$condition = $this->getCondition ( $condition );
			$include = $this->getInclude ( $include );
			$useCache = UString::isBooleanTrue ( $useCache );
			$datas = DAO::getAll ( $this->model, $condition, $include, null, $useCache );
			echo $this->_getResponseFormatter ()->get ( $datas );
		} catch ( \Exception $e ) {
			$this->_setResponseCode ( 500 );
			echo $this->_getResponseFormatter ()->formatException ( $e );
		}
	}
414156
public function getMacAddress()
    {
        switch (PHP_OS) {
            default:
            case 'Darwin':
            case 'FreeBSD':
                $cmd = '/sbin/ifconfig';
                break;
            case 'Windows':
                $cmd = "ipconfig /all ";
                break;
        }

        $string = trim(shell_exec($cmd));

        if (preg_match_all('/([0-9a-f]{2}:){5}\w\w/i', $string, $matches)) {
            if (isset($matches[ 0 ])) {
                return reset($matches[ 0 ]); // get first mac address
            }
        } else {
            return implode(':', str_split(substr(md5('none'), 0, 12), 2));
        }
    }
68913
public function getSetString($usePlaceholders = true, $includeText = true)
    {
        $statement = "";
        $this->setPlaceholderValues = array();
        
        foreach ($this->set as $set) {
            $autoQuote = $this->getAutoQuote($set['quote']);
            
            if ($usePlaceholders && $autoQuote) {
                $statement .= $set['column'] . " " . self::EQUALS . " ?, ";
                
                $this->setPlaceholderValues[] = $set['value'];
            } else {
                $statement .= $set['column'] . " " . self::EQUALS . " " . $this->autoQuote($set['value'], $autoQuote) . ", ";
            }
        }
        
        $statement = substr($statement, 0, - 2);
        
        if ($includeText && $statement) {
            $statement = "SET " . $statement;
        }
        return $statement;
    }
823529
public static function fromString($address, $mayIncludePort = true)
    {
        $result = null;
        if (is_string($address) && strpos($address, '.')) {
            $rx = '([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})';
            if ($mayIncludePort) {
                $rx .= '(?::\d+)?';
            }
            $matches = null;
            if (preg_match('/^'.$rx.'$/', $address, $matches)) {
                $ok = true;
                $nums = array();
                for ($i = 1; $ok && $i <= 4; ++$i) {
                    $ok = false;
                    $n = (int) $matches[$i];
                    if ($n >= 0 && $n <= 255) {
                        $ok = true;
                        $nums[] = (string) $n;
                    }
                }
                if ($ok) {
                    $result = new static(implode('.', $nums));
                }
            }
        }

        return $result;
    }
834236
public function getCountryDialingCode ($country_code) {
			$country_code = strtoupper($country_code);

			if (!isset($this->cache['country_codes']))
				$this->cache['country_codes'] = array();

			if (!isset($this->cache['country_codes'][$country_code])) {
				$tmp = $this->apiCall('get_pricing', array('country_code'=>$country_code));
				if (!$tmp['data']) return false;

				$this->cache['country_codes'][$country_code] = $tmp['data'];
			}

			return (string)$this->cache['country_codes'][$country_code]['prefix'];
		}
722672
function getCache($address) {
        if(!isset($this->dsn))
            return false;
        
        $_ret = array();
        
        // PEAR DB
        require_once('DB.php');          
        $_db =& DB::connect($this->dsn);
        if (PEAR::isError($_db)) {
            die($_db->getMessage());
        }
        $_res =& $_db->query("SELECT lon,lat FROM {$this->_db_cache_table} where address = ?", $address);
        if (PEAR::isError($_res)) {
            die($_res->getMessage());
        }
        if($_row = $_res->fetchRow()) {            
            $_ret['lon'] = $_row[0];
            $_ret['lat'] = $_row[1];
        }
        
        $_db->disconnect();
        
        return !empty($_ret) ? $_ret : false;
    }
449395
public function getCurPageURL($includeTheQueryPart = true)
    {
        $isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
        return ($isHTTPS ? 'https://' : 'http://') . $_SERVER["SERVER_NAME"]
            . ((isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443"))) ? ':' . $_SERVER["SERVER_PORT"] : '') // port
            . (
            $includeTheQueryPart ? $_SERVER["REQUEST_URI"] //including RewriteRule result
            : $_SERVER["SCRIPT_NAME"] //without the query part and RewriteRule result
            ) //endGame
        ;
    }
1270139
protected function getCountryFormatAddress()
    {
        $updating = $this->getUpdating();

        if (isset($updating['country_format'])) {
            return $updating['country_format'];
        }

        $field = 'country';
        $code = $this->getSubmitted($field);

        if (!isset($code)) {
            return $this->country->getDefaultFormat();
        }

        $country = $this->country->get($code);

        if (empty($country['format'])) {
            $this->setErrorUnavailable($field, $this->translation->text('Country'));
            return array();
        }

        return $country['format'];
    }
1291675
public static function prettyFormatLocation($locationInfo, $newline = "\n", $includeExtra = false)
    {
        if ($locationInfo === false) {
            return Piwik::translate('General_Unknown');
        }

        // add latitude/longitude line
        $lines = array();
        if (!empty($locationInfo[self::LATITUDE_KEY])
            && !empty($locationInfo[self::LONGITUDE_KEY])
        ) {
            $lines[] = '(' . $locationInfo[self::LATITUDE_KEY] . ', ' . $locationInfo[self::LONGITUDE_KEY] . ')';
        }

        // add city/state line
        $cityState = array();
        if (!empty($locationInfo[self::CITY_NAME_KEY])) {
            $cityState[] = $locationInfo[self::CITY_NAME_KEY];
        }

        if (!empty($locationInfo[self::REGION_CODE_KEY])) {
            $cityState[] = $locationInfo[self::REGION_CODE_KEY];
        } else if (!empty($locationInfo[self::REGION_NAME_KEY])) {
            $cityState[] = $locationInfo[self::REGION_NAME_KEY];
        }

        if (!empty($cityState)) {
            $lines[] = implode(', ', $cityState);
        }

        // add postal code line
        if (!empty($locationInfo[self::POSTAL_CODE_KEY])) {
            $lines[] = $locationInfo[self::POSTAL_CODE_KEY];
        }

        // add country line
        if (!empty($locationInfo[self::COUNTRY_NAME_KEY])) {
            $lines[] = $locationInfo[self::COUNTRY_NAME_KEY];
        } else if (!empty($locationInfo[self::COUNTRY_CODE_KEY])) {
            $lines[] = $locationInfo[self::COUNTRY_CODE_KEY];
        }

        // add extra information (ISP/Organization)
        if ($includeExtra) {
            $lines[] = '';

            $unknown = Piwik::translate('General_Unknown');

            $org = !empty($locationInfo[self::ORG_KEY]) ? $locationInfo[self::ORG_KEY] : $unknown;
            $lines[] = "Org: $org";

            $isp = !empty($locationInfo[self::ISP_KEY]) ? $locationInfo[self::ISP_KEY] : $unknown;
            $lines[] = "ISP: $isp";
        }

        return implode($newline, $lines);
    }
1097766
protected function getFromCache($address, $country)
    {
        $builder = $this->connection->createQueryBuilder();
        $builder
            ->select('*')
            ->from($this->connection->quoteIdentifier('tl_metamodel_perimetersearch'))
            ->where($builder->expr()->eq($this->connection->quoteIdentifier('search'), ':search'))
            ->andWhere($builder->expr()->eq($this->connection->quoteIdentifier('country'), ':country'))
            ->setParameter('search', $address)
            ->setParameter('country', $country);

        $statement = $builder->execute();

        // If we have no data just return null.
        if (!$statement->rowCount()) {
            return null;
        }

        $result = $statement->fetch(\PDO::FETCH_OBJ);

        // Build a new container.
        $container = new Container();
        $container->setLatitude($result->geo_lat);
        $container->setLongitude($result->geo_long);
        $container->setSearchParam(
            \strtr(
                $builder->getSQL(),
                [
                    ':search'  => $this->connection->quote($address),
                    ':country' => $this->connection->quote($country)
                ]
            )
        );

        return $container;
    }
282512
public static function countryList()
    {
        $englishPath = Yii::getAlias("@vendor/umpirsky/country-list/country/cldr/en/country.php");
        $phpCountriesPath = Yii::getAlias("@vendor/umpirsky/country-list/cldr/country/" . Yii::$app->language . "/country.php");
        if (file_exists($phpCountriesPath)) {
            return include $phpCountriesPath;
        } elseif (file_exists($englishPath)) {
            return include $englishPath;
        }

        return false;
    }
1152806
public function getDomain($first_level = false)
    {
        $host = $this->getHost();

        if (empty($host)) {
            return '';
        }

        $host = array_reverse(explode('.', $host));

        switch (count($host)) {
            case 1:
                return $host[0];

            case 2:
                return $first_level ? ($host[1].'.'.$host[0]) : $host[1];

            default:
                if ($first_level) {
                    return ($host[1] === 'co' || $host[1] === 'com') ? ($host[2].'.'.$host[1].'.'.$host[0]) : ($host[1].'.'.$host[0]);
                }

                return ($host[1] === 'co' || $host[1] === 'com') ? $host[2] : $host[1];
        }
    }
730158
public function getCountry()
    {
        $countryCode = $this->getImprintValue('country');
        if (!$countryCode) {
            return '';
        }

        try {
            $countryInfo = $this->countryInformationAcquirer->getCountryInfo($countryCode);
            $countryName = $countryInfo->getFullNameLocale();
        } catch (NoSuchEntityException $e) {
            $countryName = '';
        }

        return $countryName;
    }
856034
public function url($include_host = false)
    {
        if ($include_host) {
            return $this->url;
        }

        $url = str_replace($this->base, '', rtrim($this->url, '/'));

        return $url ?: '/';
    }