Exemple #1
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->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;
 }
Exemple #2
0
 /**
  * Save the state of the cart. This implementation uses cookie
  * so the cart contents can be manipulated on the client side as well.
  *
  * @return void
  */
 protected function save()
 {
     $sources = [];
     $ids = [];
     foreach ($this->items as $item) {
         // Break apart the source and the ID:
         list($source, $id) = explode('|', $item, 2);
         // Add the source to the source array if it is not already there:
         $sourceIndex = array_search($source, $sources);
         if ($sourceIndex === false) {
             $sourceIndex = count($sources);
             $sources[$sourceIndex] = $source;
         }
         // Encode the source into the ID as a single character:
         $ids[] = chr(65 + $sourceIndex) . $id;
     }
     // Save the cookies:
     $cookie = implode(self::CART_COOKIE_DELIM, $ids);
     $this->cookieManager->set(self::CART_COOKIE, $cookie, 0);
     $srcCookie = implode(self::CART_COOKIE_DELIM, $sources);
     $this->cookieManager->set(self::CART_COOKIE_SOURCES, $srcCookie, 0);
 }
Exemple #3
0
 /**
  * Log out the current user.
  *
  * @param string $url     URL to redirect user to after logging out.
  * @param bool   $destroy Should we destroy the session (true) or just reset it
  * (false); destroy is for log out, reset is for expiration.
  *
  * @return string     Redirect URL (usually same as $url, but modified in
  * some authentication modules).
  */
 public function logout($url, $destroy = true)
 {
     // Perform authentication-specific cleanup and modify redirect URL if
     // necessary.
     $url = $this->getAuth()->logout($url);
     // Clear out the cached user object and session entry.
     $this->currentUser = false;
     unset($this->session->userId);
     $this->cookieManager->set('loggedOut', 1);
     // Destroy the session for good measure, if requested.
     if ($destroy) {
         $this->sessionManager->destroy();
     } else {
         // If we don't want to destroy the session, we still need to empty it.
         // There should be a way to do this through Zend\Session, but there
         // apparently isn't (TODO -- do this better):
         $_SESSION = [];
     }
     return $url;
 }