class FlagGlobalCookieStorage in Flag 6.2
Same name and namespace in other branches
- 7.3 includes/flag.cookie_storage.inc \FlagGlobalCookieStorage
- 7.2 flag.inc \FlagGlobalCookieStorage
Storage handler for global flags.
Hierarchy
- class \FlagCookieStorage
- class \FlagGlobalCookieStorage
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlagCookieStorage:: |
static | function | Returns the actual storage object compatible with the flag. | |
FlagCookieStorage:: |
function | 1 | ||
FlagGlobalCookieStorage:: |
protected | function | ||
FlagGlobalCookieStorage:: |
static | function |
Deletes all the global cookies. Overrides FlagCookieStorage:: |
|
FlagGlobalCookieStorage:: |
function |
"Flags" an item. Overrides FlagCookieStorage:: |
||
FlagGlobalCookieStorage:: |
protected | function | ||
FlagGlobalCookieStorage:: |
function |
"Unflags" an item. Overrides FlagCookieStorage:: |