add further feature requirements

This commit is contained in:
Daniel Seifert 2012-02-15 13:15:28 +00:00
parent 0fa7393436
commit 224a0a97bf
4 changed files with 142 additions and 139 deletions

View File

@ -1,36 +1,36 @@
<?php
class d3GeoIP extends oxI18n
{
/**
* Current class name
*
* @var string
*/
protected $_sClassName = 'd3geoip';
<?php
class d3GeoIP extends oxI18n
{
/**
* Current class name
*
* @var string
*/
protected $_sClassName = 'd3geoip';
private $_sModId = 'd3_geoip';
/**
* Class constructor, initiates parent constructor (parent::oxI18n()).
*
* @return null
*/
public function __construct()
{
parent::__construct();
$this->init('d3geoip');
}
/**
* Class constructor, initiates parent constructor (parent::oxI18n()).
*
* @return null
*/
public function __construct()
{
parent::__construct();
$this->init('d3geoip');
}
public function getUserLocationCountryObject($sIP = false)
{
if (!$this->oCountry)
{
{
if (!$this->oCountry)
{
if (!$sIP)
$sIP = $this->getIP();
$iIPNum = $this->_getNumIp($sIP);
$sISOAlpha = $this->LoadByIPNum($iIPNum);
$iIPNum = $this->_getNumIp($sIP);
$sISOAlpha = $this->LoadByIPNum($iIPNum);
if (!$sISOAlpha)
{
@ -42,10 +42,10 @@ class d3GeoIP extends oxI18n
$this->_getLog()->setLog('info', __CLASS__, __FUNCTION__, __LINE__, 'get ISO by IP', $sIP." => ".$sISOAlpha);
$this->oCountry = $this->getCountryObject($sISOAlpha);
}
}
return $this->oCountry;
}
}
return $this->oCountry;
}
public function getIP()
{
@ -54,108 +54,108 @@ class d3GeoIP extends oxI18n
else
return $_SERVER['REMOTE_ADDR'];
}
protected function _getNumIp($sIP)
{
$aIP = explode('.',$sIP);
$iIP = ($aIP[0] * 16777216) + ($aIP[1] * 65536) + ($aIP[2] * 256) + ($aIP[3] * 1);
return $iIP;
}
public function LoadByIPNum($iIPNum)
{
$sSelect = "SELECT d3iso FROM ".$this->_sClassName." WHERE d3startipnum <= '$iIPNum' AND d3endipnum >= '$iIPNum'";
return oxDb::getDb()->getOne($sSelect);
}
public function getCountryObject($sISOAlpha)
{
$oCountry = &oxNew('oxcountry');
$sSelect = "SELECT oxid FROM ".$oCountry->getViewName()." WHERE OXISOALPHA2 = '".$sISOAlpha."' AND OXACTIVE = '1'";
$oCountry->load(oxDb::getDb()->getOne($sSelect));
return $oCountry;
}
/*
public function setUserCountry()
{
protected function _getNumIp($sIP)
{
$aIP = explode('.',$sIP);
$iIP = ($aIP[0] * 16777216) + ($aIP[1] * 65536) + ($aIP[2] * 256) + ($aIP[3] * 1);
return $iIP;
}
public function LoadByIPNum($iIPNum)
{
$sSelect = "SELECT d3iso FROM ".$this->_sClassName." WHERE d3startipnum <= '$iIPNum' AND d3endipnum >= '$iIPNum'";
return oxDb::getDb()->getOne($sSelect);
}
public function getCountryObject($sISOAlpha)
{
$oCountry = &oxNew('oxcountry');
$sSelect = "SELECT oxid FROM ".$oCountry->getViewName()." WHERE OXISOALPHA2 = '".$sISOAlpha."' AND OXACTIVE = '1'";
$oCountry->load(oxDb::getDb()->getOne($sSelect));
return $oCountry;
}
/*
public function setUserCountry()
{
if (!$this->getUser()) {
$oCountry = $this->getUserLocationCountryObject();
$oUser = &oxNew('oxuser');
$oUser->oxuser__oxcountryid = oxNew('oxfield');
$oUser->oxuser__oxcountryid->setValue($oCountry->getId());
$this->setUser($oUser);
}
return;
}
*/
public function setCountryLanguage()
{
$oCountry = $this->getUserLocationCountryObject();
$oUser = &oxNew('oxuser');
$oUser->oxuser__oxcountryid = oxNew('oxfield');
$oUser->oxuser__oxcountryid->setValue($oCountry->getId());
$this->setUser($oUser);
}
return;
}
*/
public function setCountryLanguage()
{
$this->performURLSwitch();
$this->performShopSwitch();
$this->performShopSwitch();
if (!$this->_getConfig()->getFieldData('oxactive') || !$this->_getConfig()->getValue('blChangeLang'))
return;
$oCountry = $this->getUserLocationCountryObject();
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && $this->getSession()->getVar('d3isSetLang') === null && $oCountry->getId() && $oCountry->getFieldData('d3geoiplang') > -1)
{
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && $this->getSession()->getVar('d3isSetLang') === null && $oCountry->getId() && $oCountry->getFieldData('d3geoiplang') > -1)
{
$this->_getLog()->setLog('info', __CLASS__, __FUNCTION__, __LINE__, 'set language', $this->getIP().' => '.$oCountry->getFieldData('d3geoiplang'));
oxLang::getInstance()->setTplLanguage((int) $oCountry->getFieldData('d3geoiplang'));
oxLang::getInstance()->setBaseLanguage((int) $oCountry->getFieldData('d3geoiplang'));
$this->getSession()->setVar('d3isSetLang', true);
}
}
public function setCountryCurrency()
{
oxLang::getInstance()->setTplLanguage((int) $oCountry->getFieldData('d3geoiplang'));
oxLang::getInstance()->setBaseLanguage((int) $oCountry->getFieldData('d3geoiplang'));
$this->getSession()->setVar('d3isSetLang', true);
}
}
public function setCountryCurrency()
{
if (!$this->_getConfig()->getFieldData('oxactive') || !$this->_getConfig()->getValue('blChangeCurr'))
return;
$oCountry = $this->getUserLocationCountryObject();
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && !$this->getSession()->getVar('d3isSetCurr') && $oCountry->getId() && $oCountry->getFieldData('d3geoipcur') > -1)
{
$oCountry = $this->getUserLocationCountryObject();
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && !$this->getSession()->getVar('d3isSetCurr') && $oCountry->getId() && $oCountry->getFieldData('d3geoipcur') > -1)
{
$this->_getLog()->setLog('info', __CLASS__, __FUNCTION__, __LINE__, 'set currency', $this->getIP().' => '.$oCountry->getFieldData('d3geoipcur'));
$this->getConfig()->setActShopCurrency((int) $oCountry->getFieldData('d3geoipcur'));
$this->getSession()->setVar('d3isSetCurr', true);
}
}
public function performShopSwitch()
{
$this->getConfig()->setActShopCurrency((int) $oCountry->getFieldData('d3geoipcur'));
$this->getSession()->setVar('d3isSetCurr', true);
}
}
public function performShopSwitch()
{
if (!$this->_getConfig()->getFieldData('oxactive') || !$this->_getConfig()->getValue('blChangeShop'))
return;
$oCountry = $this->getUserLocationCountryObject();
$iNewShop = $oCountry->getFieldData('d3geoipshop');
$aShopLinks = $this->getShopUrls();
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && $oCountry->getId() && $this->getConfig()->isMall() && $iNewShop > -1 && $iNewShop != $this->getConfig()->getShopId())
{
$oCountry = $this->getUserLocationCountryObject();
$iNewShop = $oCountry->getFieldData('d3geoipshop');
$aShopLinks = $this->getShopUrls();
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && $oCountry->getId() && $this->getConfig()->isMall() && $iNewShop > -1 && $iNewShop != $this->getConfig()->getShopId())
{
$oNewConf = new oxConfig();
$oNewConf->setShopId($iNewShop);
$oNewConf->init();
$this->getConfig()->onShopChange();
if (!$this->getSession()->getVar('d3isSetLang') && $oCountry->getFieldData('d3geoiplang') > -1)
$sLangId = $oCountry->getFieldData('d3geoiplang');
else
$sLangId = '';
$this->_getLog()->setLog('info', __CLASS__, __FUNCTION__, __LINE__, 'change shop', $this->getIP().' => '.$oNewConf->getShopHomeUrl($sLangId));
header("Location: ".$oNewConf->getShopHomeUrl($sLangId));
exit();
}
}
}
}
public function performURLSwitch()
{
@ -167,7 +167,7 @@ class d3GeoIP extends oxI18n
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && $oCountry->getId() && $oCountry->getFieldData('d3geoipurl') && strlen(trim($oCountry->getFieldData('d3geoipurl'))) > 0)
{
$sNewUrl = $oCountry->getFieldData('d3geoipurl');
$this->_getLog()->setLog('info', __CLASS__, __FUNCTION__, __LINE__, 'change url', $this->getIP().' => '.$oCountry->getFieldData('d3geoipurl'));
header("Location: ".$sNewUrl);
@ -175,17 +175,17 @@ class d3GeoIP extends oxI18n
}
}
public function getShopUrls()
{
$oShoplist = oxNew( 'oxshoplist' );
$oShoplist->getList();
$aShopUrls = array();
foreach ( $oShoplist as $sId => $oShop ) {
$aShopUrls[$sId] = $this->getConfig()->getShopConfVar( 'sMallShopURL', $sId );
}
return $aShopUrls;
}
public function getShopUrls()
{
$oShoplist = oxNew( 'oxshoplist' );
$oShoplist->getList();
$aShopUrls = array();
foreach ( $oShoplist as $sId => $oShop ) {
$aShopUrls[$sId] = $this->getConfig()->getShopConfVar( 'sMallShopURL', $sId );
}
return $aShopUrls;
}
protected function _getConfig()
{

View File

@ -1,11 +1,11 @@
<?php
class d3_oxcmp_cur_geoip extends d3_oxcmp_cur_geoip_parent
{
<?php
class d3_oxcmp_cur_geoip extends d3_oxcmp_cur_geoip_parent
{
private $_sModId = 'd3_geoip';
public function init()
{
public function init()
{
if (d3_cfg_mod::get($this->_sModId)->getValue('blDebugmodeGlobal'))
{
$oGeoIp = oxNew('d3geoip');
@ -14,9 +14,9 @@ class d3_oxcmp_cur_geoip extends d3_oxcmp_cur_geoip_parent
$oLocation = oxNew('d3geoip');
//$oLocation->setUserCountry();
$oLocation->setCountryCurrency();
return parent::init();
}
$oLocation->setCountryCurrency();
return parent::init();
}
}

View File

@ -1,13 +1,13 @@
<?php
class d3_oxcmp_lang_geoip extends d3_oxcmp_lang_geoip_parent
{
public function init()
{
<?php
class d3_oxcmp_lang_geoip extends d3_oxcmp_lang_geoip_parent
{
public function init()
{
$oLocation = oxNew('d3geoip');
//$oLocation->setUserCountry();
$oLocation->setCountryLanguage();
return parent::init();
}
//$oLocation->setUserCountry();
$oLocation->setCountryLanguage();
return parent::init();
}
}

View File

@ -0,0 +1,3 @@
blForceSessionStart nur bei Anwendung von GeoIP
auch nicht aktive Länder konfigurierbar (um auch nicht erlaubte Zugriffe abzufangen)
IP-Syntaxcheck bei Eingabe im Admin