Example #1
0
 /**
  * get instance
  *
  *
  * @return Application_Model_CountryMapper
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
0
 /**
  * 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();
     }
 }
Example #3
0
 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);
     }
 }
 /**
  * Configuration action
  */
 public function configAction()
 {
     //read data from request
     $data = $this->getRequest()->getPost('data');
     $inputHashChangePost = $this->_request->getParam('inputHashChangePost');
     $inputHashChangeGet = $this->_request->getParam('inputHashChangeGet');
     //check if cancel button is pressed
     if ($this->_formHelper->isCancel()) {
         //cancel form
         return $this->_formHelper->returnCancel($this->view->url(array('action' => 'index')), $this->translate('Action canceled'));
     }
     if ($this->getRequest()->getParam("type") == 'contact') {
         $module_name = "contact";
     } else {
         if ($this->getRequest()->getParam("type") == 'newsletter') {
             $module_name = "newsletter";
         } else {
             if ($this->getRequest()->getParam("type") == 'blog') {
                 $module_name = "blog";
             } else {
                 throw new Exception("Contact module not found");
             }
         }
     }
     //read contact module
     $module = new Application_Model_Module();
     if (!Application_Model_ModuleMapper::getInstance()->findByCode($module_name, $module)) {
         throw new Exception("Contact module not found");
     }
     $this->view->data = array('email' => $module->get_settings('email'));
     $this->view->data['type'] = $module_name;
     $this->view->emailTransportTypeOptions = Application_Model_Application::getEmailTransportTypeOptions();
     //postback - save?
     if ($this->_formHelper->isSave()) {
         $formToEmails = new Contact_Form_ConfigToEmailsWrapper($data['email']['to_emails']);
         $formParameters = new Contact_Form_ConfigParameters($data['email']['parameters'], null, $data['email']['transport']);
         if ($module_name == 'contact') {
             $formEmail = new Contact_Form_ConfigEmail($data['email']);
         } elseif ($module_name == 'newsletter') {
             $formEmail = new Contact_Form_ConfigEmailNewsletter($data['email']);
         } elseif ($module_name == 'blog') {
             $formEmail = new Blog_Form_ConfigEmail($data['email']);
         }
         //check if valid
         if ($formEmail->isValid() && $formParameters->isValid() && $formToEmails->isValid()) {
             $data['email'] = $formEmail->getValues();
             $data['email']['parameters'] = $formParameters->getValues();
             $data['email']['to_emails'] = $formToEmails->getValues();
             $lang = new Translation_Model_Lang();
             if (!Translation_Model_LangMapper::getInstance()->findByCode(CURR_LANG, $lang)) {
                 throw new Exception('No language for this code.');
             }
             Translation_Model_TranslationMapper::getInstance()->save('mailtextRespondContactTranslationkey', $lang->get_id(), $data['email']['mailtext_respond_contact'], 'global');
             $data['email']['mailtext_respond_contact'] = 'mailtextRespondContactTranslationkey';
             Translation_Model_TranslationMapper::getInstance()->save('landingPageText', $lang->get_id(), $data['email']['landing_page_text'], 'global');
             $data['email']['landing_page_text'] = 'landingPageText';
             Translation_Model_TranslationMapper::getInstance()->save('subjectContactTranslationkey', $lang->get_id(), $data['email']['subject_contact'], 'global');
             $data['email']['subject_contact'] = 'subjectContactTranslationkey';
             //create module entity object
             $settings = $module->get_settings();
             $settings['email'] = $data['email'];
             $module->set_settings(json_encode($settings));
             $module->set_data(json_encode($module->get_data()));
             //new entity
             Application_Model_ModuleMapper::getInstance()->save($module);
             //save done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'config', 'inputHashChangeGet' => $inputHashChangePost)), $this->translate('Configuration saved.'));
         } else {
             //we have errors - return json or continue
             $messages = $formEmail->getMessages();
             $messages['parameters'] = $formParameters->getMessages();
             $messages['to_emails'] = $formToEmails->getMessages();
             $this->view->data = $data;
             $this->_formHelper->returnError($messages);
         }
     }
     if (isset($inputHashChangeGet) && $inputHashChangeGet != '') {
         $this->view->inputHashChange = $inputHashChangeGet;
     } else {
         $this->view->inputHashChange = "email-config";
     }
     //country assign
     $countries = new Application_Model_Country();
     $countries = Application_Model_CountryMapper::getInstance()->getAllCountries(CURR_LANG);
     $this->view->countries = $countries;
     $this->view->languages = Application_Model_TranslateMapper::getInstance()->getLanguages();
     $this->view->fields = Contact_Form_Contact::getFields();
 }