Example #1
0
 /**
  * Grabs a param from cookie.
  *
  * @param string $param
  * @param mixed $default
  * @return mixed
  */
 public function __invoke($param = null, $default = null)
 {
     if ($this->request instanceof HttpRequest) {
         $cookie = $this->request->getCookie();
         if ($param === null) {
             return $cookie;
         }
         if ($cookie->offsetExists($param)) {
             return $cookie->get($param);
         }
         return $default;
     }
 }
Example #2
0
 /**
  * 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;
 }