/** * Set default value * * @param string $dataCountryKey * @return mixed */ public function setDefault($dataCountryKey = 'country') { $emailParams = $this->_settings; if ($this->_actionController->getRequest()->isPost() || !isset($emailParams['ip_country_detection']) || $emailParams['ip_country_detection'] != 'yes') { return; } $ip = HCMS_Utils::getRealIpAddr(); $myCountry = new Application_Model_Country(); if (Application_Model_CountryMapper::getInstance()->getCountryByGeoIp($ip, $myCountry)) { $this->_actionController->view->data[$dataCountryKey] = $myCountry->get_code2(); } }
/** * Check permission per IP address */ protected function _checkIP() { //fetch ip restriction from application.ini $ipRestriction = $this->_getBootstrapOption('ip_restriction'); if (!$ipRestriction || $ipRestriction == '') { return false; } $ipRestrictions = explode(",", $ipRestriction); //Check permission per IP address if (!in_array(HCMS_Utils::getRealIpAddr(), $ipRestrictions)) { throw new Zend_Controller_Action_Exception("You are not allowed to access this page", 403); } }
protected function _initLanguage() { $singleLang = Zend_Controller_Front::getInstance()->getParam('singleLang'); if (isset($singleLang) && $singleLang != "") { //1. get language from app.ini $language = $singleLang; $this->getRequest()->setParam("lang", $singleLang); } else { //1. get language from request $language = $this->getRequest()->getParam("lang"); } //$this->_log("Request: " . json_encode($this->getRequest()->getParams()), Zend_Log::DEBUG); if ($language == '') { $language = null; } //2. get language from cookie if (!isset($language)) { $language = $this->getRequest()->getCookie("saved_lang", null); } //3. get from geoip if (!isset($language)) { $country = new Application_Model_Country(); if (Application_Model_CountryMapper::getInstance()->getCountryByGeoIp(HCMS_Utils::getRealIpAddr(), $country)) { $language = strtolower($country->get_def_lang()); } } //4. get default if (!isset($language)) { $language = $this->_getPrimaryLang(); } //check if lang available if (!HCMS_Translate_Adapter_Db::isLangAvailable($language, $this->_isFrontEnd)) { $language = $this->_getPrimaryLang(); } //redirect if lang is not in url if ($language != $this->getRequest()->getParam("lang")) { //redirect only if lang not exists...otherwise let it 404 if (!$this->getRequest()->getParam("lang")) { $this->_log("redirecting to {$language}", Zend_Log::DEBUG); $redirector = new Zend_Controller_Action_Helper_Redirector(); $redirector->gotoRouteAndExit(array('lang' => $language), 'default', false); } } //activate lang HCMS_Translate_Adapter_Db::activate($language); //store lang in cookie $cookieRes = setcookie('saved_lang', $language, time() + 3600, '/', null, false, true); if (!$cookieRes) { $this->_logger->log("Error storing lang cookie", Zend_Log::WARN); } //and in router Zend_Controller_Front::getInstance()->getRouter()->setGlobalParam('lang', $language); //set view and js var if ($this->view) { $this->view->availableLang = Application_Model_TranslateMapper::getInstance()->getLanguages(); $this->view->currLang = $language; $this->view->headScript()->appendScript("var CURR_LANG = '" . $language . "';"); $this->view->singleLang = $this->isSingleLang(); //$this->addLinkAlternateLang(); } //define php const if (!defined("CURR_LANG")) { define("CURR_LANG", $language); } }