当前位置: 首页>>代码示例>>PHP>>正文


PHP FrontController::isInWhitelistForGeolocation方法代码示例

本文整理汇总了PHP中FrontController::isInWhitelistForGeolocation方法的典型用法代码示例。如果您正苦于以下问题:PHP FrontController::isInWhitelistForGeolocation方法的具体用法?PHP FrontController::isInWhitelistForGeolocation怎么用?PHP FrontController::isInWhitelistForGeolocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FrontController的用法示例。


在下文中一共展示了FrontController::isInWhitelistForGeolocation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init


//.........这里部分代码省略.........
			throw new PrestaShopException((sprintf(Tools::displayError('Current theme unavailable "%s". Please check your theme directory name and permissions.'), basename(rtrim(_PS_THEME_DIR_, '/\\')))));

		if (Configuration::get('PS_GEOLOCATION_ENABLED'))
			if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault))
				$this->context->country = $newDefault;

		$currency = Tools::setCurrency($this->context->cookie);

		if (isset($_GET['logout']) || ($this->context->customer->logged && Customer::isBanned($this->context->customer->id)))
		{
			$this->context->customer->logout();

			Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
		}
		elseif (isset($_GET['mylogout']))
		{
			$this->context->customer->mylogout();
			Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
		}

		/* Cart already exists */
		if ((int)$this->context->cookie->id_cart)
		{
			$cart = new Cart($this->context->cookie->id_cart);
			if ($cart->OrderExists())
			{
				unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
				$this->context->cookie->check_cgv = false;
			}
			/* Delete product of cart, if user can't make an order from his country */
			elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) &&
					!in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) &&
					$cart->nbProducts() && intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 &&
					!FrontController::isInWhitelistForGeolocation() &&
					!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1')))
				unset($this->context->cookie->id_cart, $cart);
			// update cart values
			elseif ($this->context->cookie->id_customer != $cart->id_customer || $this->context->cookie->id_lang != $cart->id_lang || $currency->id != $cart->id_currency)
			{
				if ($this->context->cookie->id_customer)
					$cart->id_customer = (int)($this->context->cookie->id_customer);
				$cart->id_lang = (int)($this->context->cookie->id_lang);
				$cart->id_currency = (int)$currency->id;
				$cart->update();
			}
			/* Select an address if not set */
			if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 ||
				!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $this->context->cookie->id_customer)
			{
				$to_update = false;
				if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0)
				{
					$to_update = true;
					$cart->id_address_delivery = (int)Address::getFirstCustomerAddressId($cart->id_customer);
				}
				if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0)
				{
					$to_update = true;
					$cart->id_address_invoice = (int)Address::getFirstCustomerAddressId($cart->id_customer);
				}
				if ($to_update)
					$cart->update();
			}
		}

		if (!isset($cart) || !$cart->id)
开发者ID:,项目名称:,代码行数:67,代码来源:

示例2: geolocationManagement

 protected function geolocationManagement($default_country)
 {
     if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
         /* Check if Maxmind Database exists */
         if (file_exists(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat')) {
             if (!isset($this->context->cookie->iso_code_country) || isset($this->context->cookie->iso_code_country) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))) {
                 include_once _PS_GEOIP_DIR_ . 'geoipcity.inc';
                 $gi = geoip_open(realpath(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat'), GEOIP_STANDARD);
                 $record = geoip_record_by_addr($gi, Tools::getRemoteAddr());
                 if (is_object($record)) {
                     if (!in_array(strtoupper($record->country_code), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && !FrontController::isInWhitelistForGeolocation()) {
                         if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) {
                             $this->restrictedCountry = true;
                         } elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) {
                             $this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => $record->country_name));
                         }
                     } else {
                         $has_been_set = !isset($this->context->cookie->iso_code_country);
                         $this->context->cookie->iso_code_country = strtoupper($record->country_code);
                     }
                 }
             }
             if (isset($this->context->cookie->iso_code_country) && $this->context->cookie->iso_code_country && !Validate::isLanguageIsoCode($this->context->cookie->iso_code_country)) {
                 $this->context->cookie->iso_code_country = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
             }
             if (isset($this->context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($this->context->cookie->iso_code_country)))) {
                 /* Update defaultCountry */
                 if ($default_country->iso_code != $this->context->cookie->iso_code_country) {
                     $default_country = new Country($id_country);
                 }
                 if (isset($has_been_set) && $has_been_set) {
                     $this->context->cookie->id_currency = (int) Currency::getCurrencyInstance($default_country->id_currency ? (int) $default_country->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id;
                 }
                 return $default_country;
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_ && !FrontController::isInWhitelistForGeolocation()) {
                 $this->restrictedCountry = true;
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_ && !FrontController::isInWhitelistForGeolocation()) {
                 $this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => 'Undefined'));
             }
         } else {
             Configuration::updateValue('PS_GEOLOCATION_ENABLED', 0);
         }
     }
     return false;
 }
开发者ID:MacFlay,项目名称:Presta-Domowy,代码行数:45,代码来源:FrontController.php

示例3: geolocationManagement

 /**
  * Geolocation management.
  *
  * @param Country $defaultCountry
  *
  * @return Country|false
  */
 protected function geolocationManagement($defaultCountry)
 {
     if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
         /* Check if Maxmind Database exists */
         if (@filemtime(_PS_GEOIP_DIR_ . _PS_GEOIP_CITY_FILE_)) {
             if (!isset($this->context->cookie->iso_code_country) || isset($this->context->cookie->iso_code_country) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))) {
                 $reader = new GeoIp2\Database\Reader(_PS_GEOIP_DIR_ . _PS_GEOIP_CITY_FILE_);
                 $record = $reader->city(Tools::getRemoteAddr());
                 if (is_object($record)) {
                     if (!in_array(strtoupper($record->country->isoCode), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && !FrontController::isInWhitelistForGeolocation()) {
                         if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) {
                             $this->restrictedCountry = Country::GEOLOC_FORBIDDEN;
                         } elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) {
                             $this->restrictedCountry = Country::GEOLOC_CATALOG_MODE;
                             $this->warning[] = sprintf($this->l('You cannot place a new order from your country (%s).'), $record->country->name);
                         }
                     } else {
                         $hasBeenSet = !isset($this->context->cookie->iso_code_country);
                         $this->context->cookie->iso_code_country = strtoupper($record->country->isoCode);
                     }
                 }
             }
             if (isset($this->context->cookie->iso_code_country) && $this->context->cookie->iso_code_country && !Validate::isLanguageIsoCode($this->context->cookie->iso_code_country)) {
                 $this->context->cookie->iso_code_country = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
             }
             if (isset($this->context->cookie->iso_code_country) && ($idCountry = (int) Country::getByIso(strtoupper($this->context->cookie->iso_code_country)))) {
                 /* Update defaultCountry */
                 if ($defaultCountry->iso_code != $this->context->cookie->iso_code_country) {
                     $defaultCountry = new Country($idCountry);
                 }
                 if (isset($hasBeenSet) && $hasBeenSet) {
                     $this->context->cookie->id_currency = (int) ($defaultCountry->id_currency ? (int) $defaultCountry->id_currency : (int) Configuration::get('PS_CURRENCY_DEFAULT'));
                 }
                 return $defaultCountry;
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_ && !FrontController::isInWhitelistForGeolocation()) {
                 $this->restrictedCountry = Country::GEOLOC_FORBIDDEN;
             } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_ && !FrontController::isInWhitelistForGeolocation()) {
                 $this->restrictedCountry = Country::GEOLOC_CATALOG_MODE;
                 $this->warning[] = sprintf($this->l('You cannot place a new order from your country (%s).'), isset($record->country->name) && $record->country->name ? $record->country->name : $this->l('Undefined'));
             }
         }
     }
     return false;
 }
开发者ID:M03G,项目名称:PrestaShop,代码行数:51,代码来源:FrontController.php


注:本文中的FrontController::isInWhitelistForGeolocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。