/** * 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 (!Mobile::enabled() || !Mobile::detect()) { return false; } $urlHelper = $this->getView()->plugin('serverurl'); $currentUrl = rtrim($urlHelper(true), '?'); $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->Site->theme; $mobileTheme = isset($this->config->Site->mobile_theme) ? $this->config->Site->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 && Mobile::detect() ? 'mobile' : 'standard'; } // Save the current setting to a cookie so it persists: $_COOKIE['ui'] = $selectedUI; setcookie('ui', $selectedUI, null, '/'); // 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->Site->alternate_themes)) { // Check the alternate theme settings for a match: $parts = explode(',', $this->config->Site->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; }