Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. <?php
  2. class AppController extends Controller {
  3.    
  4.     var $components = array ('Cookie','Session','Geoip');
  5.    
  6.     var $dbconfigs = array ('deu' => array(
  7.                             'driver' => 'mysql',
  8.                             'persistent' => false,
  9.                             'host' => 'localhost',
  10.                             'login' => 'root',
  11.                             'password' => '',
  12.                             'database' => 'countitdown_deu'),
  13.                            
  14.                             'eng' => array(
  15.                             'driver' => 'mysql',
  16.                             'persistent' => false,
  17.                             'host' => 'localhost',
  18.                             'login' => 'root',
  19.                             'password' => '',
  20.                             'database' => 'countitdown_eng')
  21.                             );
  22.                            
  23.    
  24.     function beforeFilter() {
  25.         $this->_setLanguage();
  26.     }
  27.      
  28.     function _setLanguage() {
  29.        
  30.         $ip = $this->Geoip->findIp();
  31.         if (isset($ip)) {
  32.          $geo = $this->Geoip->lookupIp($ip);
  33.         }
  34.      
  35.         if ($this->Cookie->read('lang') && !$this->Session->check('Config.language')) {
  36.             $this->Session->write('Config.language', $this->Cookie->read('lang'));
  37.         }
  38.         else if (isset($this->params['language']) && ($this->params['language']
  39.                  !=  $this->Session->read('Config.language'))) {
  40.      
  41.             $this->Session->write('Config.language', $this->params['language']);
  42.             $this->Cookie->write('lang', $this->params['language'], false, '40 days');
  43.            
  44.         }
  45.         else if (isset($geo) &&  ($geo != "") && (!$this->Cookie->read('lang') && !$this->Session->check('Config.language'))){
  46.            
  47.             $this->Session->write('Config.language', $geo['country_code3']);
  48.             $this->Cookie->write('lang', $geo['country_code3'], false, '40 days');
  49.         }
  50.        
  51.         Configure::write('Config.language',$this->Session->read('Config.language'));
  52.      
  53.      
  54.          if ($this->Session->read('Config.language') == 'deu') {
  55.              
  56.              $db = ConnectionManager::getDataSource('default');
  57.              $db->disconnect();
  58.              $db->setConfig($this->dbconfigs['deu']);
  59.              $db->connect();
  60.          }
  61.      
  62.     }
  63.    
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement