You are here

class FlagGlobalCookieStorage in Flag 6.2

Same name and namespace in other branches
  1. 7.3 includes/flag.cookie_storage.inc \FlagGlobalCookieStorage
  2. 7.2 flag.inc \FlagGlobalCookieStorage

Storage handler for global flags.

Hierarchy

Expanded class hierarchy of FlagGlobalCookieStorage

File

./flag.inc, line 1832
Implements various flags. Uses object oriented style inspired by that of Views 2.

View source
class FlagGlobalCookieStorage extends FlagCookieStorage {
  function flag($content_id) {
    $cookie_key = $this
      ->cookie_key($content_id);
    setcookie($cookie_key, 1, time() + $this
      ->get_lifetime(), base_path());
    $_COOKIE[$cookie_key] = 1;
  }
  function unflag($content_id) {
    $cookie_key = $this
      ->cookie_key($content_id);
    setcookie($cookie_key, 0, 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($content_id) {
    return 'flag_global_' . $this->flag->name . '_' . $content_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