You are here

class FlagGlobalCookieStorage in Flag 7.3

Same name and namespace in other branches
  1. 6.2 flag.inc \FlagGlobalCookieStorage
  2. 7.2 flag.inc \FlagGlobalCookieStorage

Storage handler for global flags.

Hierarchy

Expanded class hierarchy of FlagGlobalCookieStorage

File

includes/flag.cookie_storage.inc, line 68
Contains the FlagCookieStorage class.

View source
class FlagGlobalCookieStorage extends FlagCookieStorage {
  function flag($entity_id) {
    $cookie_key = $this
      ->cookie_key($entity_id);
    setcookie($cookie_key, 1, REQUEST_TIME + $this
      ->get_lifetime(), base_path());
    $_COOKIE[$cookie_key] = 1;
  }
  function unflag($entity_id) {
    $cookie_key = $this
      ->cookie_key($entity_id);
    setcookie($cookie_key, 0, REQUEST_TIME + $this
      ->get_lifetime(), base_path());
    $_COOKIE[$cookie_key] = 0;
  }

  // Global flags persist for the length of the minimum cache lifetime.
  protected function get_lifetime() {
    $cookie_lifetime = variable_get('cache', 0) ? variable_get('cache_lifetime', 0) : -1;

    // Do not let the cookie lifetime be 0 (which is the no cache limit on
    // anonymous page caching), since it would expire immediately. Usually
    // the no cache limit means caches are cleared on cron, which usually runs
    // at least once an hour.
    if ($cookie_lifetime == 0) {
      $cookie_lifetime = 3600;
    }
    return $cookie_lifetime;
  }
  protected function cookie_key($entity_id) {
    return 'flag_global_' . $this->flag->name . '_' . $entity_id;
  }

  /**
   * Deletes all the global cookies.
   */
  static function drop() {
    foreach ($_COOKIE as $key => $value) {
      if (strpos($key, 'flag_global_') === 0) {
        setcookie($key, FALSE, 0, base_path());
        unset($_COOKIE[$key]);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlagCookieStorage::factory static function Returns the actual storage object compatible with the flag.
FlagCookieStorage::__construct function 1
FlagGlobalCookieStorage::cookie_key protected function
FlagGlobalCookieStorage::drop static function Deletes all the global cookies. Overrides FlagCookieStorage::drop
FlagGlobalCookieStorage::flag function "Flags" an item. Overrides FlagCookieStorage::flag
FlagGlobalCookieStorage::get_lifetime protected function
FlagGlobalCookieStorage::unflag function "Unflags" an item. Overrides FlagCookieStorage::unflag