public function beforeAction($action) { $device = new MobileDetect(); $theme = ['class' => 'yii\\base\\Theme', 'basePath' => '@app/themes/basic', 'baseUrl' => '@web/themes/basic', 'pathMap' => ['@app/views' => ['@app/themes/' . ($device->isMobile() ? 'mobile' : 'special'), '@app/themes/basic']]]; \Yii::$app->getView()->theme = \Yii::createObject($theme); return true; }
/** * @Flow\Around("method(TYPO3\Flow\Mvc\ActionRequest->isTablet())") * @param JoinPointInterface $joinPoint * @return boolean */ public function isTablet(JoinPointInterface $joinPoint) { if ($this->mobileDetection === NULL) { $this->initializeMobileDetection(); } return $this->mobileDetection->isTablet(); }
public function render() { if ($this->mobileDetection->isMobile()) { return $this->renderThenChild(); } else { return $this->renderElseChild(); } }
/** * @return bool */ public function isMobile() { if (class_exists(MobileDetect::class)) { $detect = new MobileDetect(); return $detect->isMobile() || $detect->isTablet(); } return true; }
/** * SetUp method * * @return void */ public function setUp() { parent::setUp(); Request::addDetector('mobile', function ($request) { $detector = new MobileDetect(); return $detector->isMobile(); }); Request::addDetector('tablet', function ($request) { $detector = new MobileDetect(); return $detector->isTablet(); }); $this->event = new Event('Controller.beforeFilter'); $this->Controller = new MobileComponentTestController(new Request()); $this->Controller->request->session()->delete('User'); Configure::delete('User'); }
/** * Checks & sets the type of device used to access to the app. */ private function setDevice() { try { if (class_exists('Detection\\MobileDetect')) { $device = 'desktop'; $mobile_detect = new Detection\MobileDetect(); if ($mobile_detect->isMobile()) { $device = 'mobile'; } $this->device = $device; } else { throw new Exception('Error while instantiating the "Mobile_Detect" class.'); } } catch (Exception $e) { dump($e); } }
public function isMobile() { $detect = new Mobile_Detect(); return $detect->isMobile(); }
/** * Filter the parsed result to the schema. * * @param \Detection\MobileDetect $parsed * @return array */ public function filter($parsed) { $filtered = array(); // Filtering mechanishm for MobileDetect 2.* versions. $filter = function ($items) use($parsed) { // Play down the $parsed->is('Android'); mechanishm. foreach ($items as $key => $regex) { if ($parsed->is($key)) { return $key; } } return null; }; // Operating system's family. $filtered['osFamily'] = $filter($parsed->getOperatingSystems()); // Browser's family. $filtered['browserFamily'] = $filter($parsed->getBrowsers()); // Just 'mobile' kind devices. if ($parsed->isMobile() and !$parsed->isTablet()) { $filtered['isMobile'] = true; $filtered['mobileGrade'] = $parsed->mobileGrade(); $filtered['deviceModel'] = $filter($parsed->getPhoneDevices()); } elseif ($parsed->isTablet()) { $filtered['isTablet'] = true; $filtered['mobileGrade'] = $parsed->mobileGrade(); $filtered['deviceModel'] = $filter($parsed->getTabletDevices()); } // Clear the generic and null values. $filtered = array_filter(array_filter($filtered, function ($value) { return !preg_match('%^generic%i', $value); })); return $filtered; }
/** * Lists all Password models. * * @return mixed */ public function actionIndex() { if (Yii::$app->params['single_user_mode'] === FALSE) { if (Yii::$app->user->isGuest === true) { return $this->redirect(['/site/login']); } PasswordController::teamSecretCheck(); $searchModel = new PasswordSearch(); if (intval(Yii::$app->user->getIdentity()->is_admin) !== 1) { $account_credential_ids = $this->getAccountCredentials(Yii::$app->user->id); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $account_credential_ids); } else { $dataProvider = $searchModel->search(Yii::$app->request->queryParams); } } else { PasswordController::teamSecretCheck(); $searchModel = new PasswordSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); } $mobile_detect = new MobileDetect(); if ($mobile_detect->isMobile() === false) { return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } else { return $this->render('index_mobile', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } }
/** * * @author http://mobiforge.com/developing/story/lightweight-device-detection-php * @return bool */ protected function detectMobile() { $context = Context::getInstance(); if (!$context->get("xmlnuke.DETECTMOBILE")) { return false; } if ($context->get('xmlmobile') != '') { $context->setSession('xmlnuke.USEMOBILE', $context->get('xmlmobile') == "true"); } if ($context->getSession('xmlnuke.USEMOBILE') === false || $context->getSession('xmlnuke.USEMOBILE') === true) { return $context->getSession('xmlnuke.USEMOBILE'); } $detect = new MobileDetect(); // Any mobile device (phones or tablets). return $detect->isMobile(); }