/** * Test detection wrapping. * * @return void */ public function testDetection() { $detector = $this->getMock('uagent_info', ['DetectMobileLong']); $detector->expects($this->once())->method('DetectMobileLong')->will($this->returnValue(true)); $mobile = new Mobile($detector); $this->assertTrue($mobile->detect()); }
/** * Return the mobile version of the current URL if the user is on a mobile device * and might want to switch over. Return false when not on a mobile device. * * @return string */ public function __invoke() { // Do nothing special if we're not on a mobile device or no mobile theme is // enabled: if (!$this->mobile->enabled() || !$this->mobile->detect()) { return false; } $urlHelper = $this->getView()->plugin('serverurl'); $currentUrl = $urlHelper(true); $currentUrl = preg_replace(['/\\&ui=[^&]*/', '/\\?ui=[^&]*\\&?/'], ['', '?'], $currentUrl); $currentUrl = rtrim($currentUrl, '?'); $currentUrl .= strstr($currentUrl, '?') ? '&' : '?'; return $currentUrl .= 'ui=mobile'; }
/** * Support method for init() -- figure out which theme option is active. * * @param Request $request Request object (for obtaining user parameters). * * @return string */ protected function pickTheme(Request $request) { // Load standard configuration options: $standardTheme = $this->config->theme; $mobileTheme = $this->mobile->enabled() ? $this->config->mobile_theme : false; // Find out if the user has a saved preference in the POST, URL or cookies: $selectedUI = $request->getPost()->get('ui', $request->getQuery()->get('ui', isset($request->getCookie()->ui) ? $request->getCookie()->ui : null)); if (empty($selectedUI)) { $selectedUI = $mobileTheme && $this->mobile->detect() ? 'mobile' : 'standard'; } // Save the current setting to a cookie so it persists: $this->cookieManager->set('ui', $selectedUI); // Do we have a valid mobile selection? if ($mobileTheme && $selectedUI == 'mobile') { return $mobileTheme; } // Do we have a non-standard selection? if ($selectedUI != 'standard' && isset($this->config->alternate_themes)) { // Check the alternate theme settings for a match: $parts = explode(',', $this->config->alternate_themes); foreach ($parts as $part) { $subparts = explode(':', $part); if (trim($subparts[0]) == trim($selectedUI) && isset($subparts[1]) && !empty($subparts[1])) { return $subparts[1]; } } } // If we got this far, we either have a standard option or the user chose // an invalid non-standard option; either way, we need to default to the // standard theme: return $standardTheme; }