/** * for this helper the controller has to be passed as reference * for manual startup with $disableStartup = true (requires this to be called prior to any other method) * 2009-12-19 ms */ public function startup(Controller $Controller = null) { /** DATA PREPARATION **/ if (!empty($this->Controller->request->data) && !Configure::read('DataPreparation.notrim')) { $this->Controller->request->data = $this->trimDeep($this->Controller->request->data); } if (!empty($this->Controller->request->query) && !Configure::read('DataPreparation.notrim')) { $this->Controller->request->query = $this->trimDeep($this->Controller->request->query); } if (!empty($this->Controller->request->params['named']) && !Configure::read('DataPreparation.notrim')) { $this->Controller->request->params['named'] = $this->trimDeep($this->Controller->request->params['named']); } if (!empty($this->Controller->request->params['pass']) && !Configure::read('DataPreparation.notrim')) { $this->Controller->request->params['pass'] = $this->trimDeep($this->Controller->request->params['pass']); } /** Information Gathering **/ if (!Configure::read('App.disableMobileDetection') && ($mobile = $this->Session->read('Session.mobile')) === null) { App::uses('UserAgentLib', 'Tools.Lib'); $UserAgentLib = new UserAgentLib(); $mobile = (int) $UserAgentLib->isMobile(); $this->Session->write('Session.mobile', $mobile); } /** Layout **/ if ($this->Controller->request->is('ajax')) { $this->Controller->layout = 'ajax'; } }
public function detectByTools() { $isMobile = $this->Session->read('Session.mobile'); if ($isMobile !== null) { return $isMobile; } App::uses('UserAgentLib', 'Tools.Lib'); $UserAgentLib = new UserAgentLib(); $mobile = (int) $UserAgentLib->isMobile(); $this->Session->write('Session.mobile', $mobile); return $mobile; }
/** * Simple auto-detection based on Tools plugin or vendor classes. * * @param string $engine * @return bool Success */ public function detectByVendor($engine) { $isMobile = $this->Session->read('Session.mobile'); if ($isMobile !== null) { return (bool) $isMobile; } // Deprecated - the vendor libs are far more accurate and up to date if ($engine === 'tools') { App::uses('UserAgentLib', 'Tools.Lib'); $UserAgentLib = new UserAgentLib(); return (bool) $UserAgentLib->isMobile(); } App::import('Vendor', 'Tools.MobileDetect', ['file' => 'MobileDetect/Mobile_Detect.php']); $MobileDetect = new Mobile_Detect(); $result = empty($this->settings['mobile']) ? 0 : 1; if (in_array('mobile', $this->settings['mobile'])) { $result &= $MobileDetect->isMobile(); } if (in_array('tablet', $this->settings['mobile'])) { $result |= $MobileDetect->isTablet(); } else { $result &= !$MobileDetect->isTablet(); } $this->Session->write('Session.mobile', (bool) $result); return (bool) $result; }