<?php
/**
*
* @author Benjamin Gillissen <hide@address.com>
*
*
* **************************************************************
Copyright (C) 2009 Benjamin Gillissen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details at:
http://www.gnu.org/copyleft/gpl.html
* **************************************************************
*/
class cookies {
private static $_COOK;
private static function load($cookref=NULL){
$cookref = self::getref($cookref);
if ( FALSE === $cookref ){
errors::raise('Invalid Cookref, abording load', CORE_LOG_ERROR, 'COOK');
return FALSE;
}
if ( !isset(self::$_COOK[$cookref]) ){
if ( $cookref == 'failsave' ){
errors::raise('No Default CookRef specified, using failsave (nocrypt, one year)', CORE_LOG_WARNING, 'COOK');
$conf = Array( 'cipher' => FALSE,
'expire' => 60*60*24*256);
} else {
$conf = configs::get('cookies', $cookref);
}
if ( FALSE !== $conf['cipher'] ){
self::$_COOK[$cookref] = new cooky($cookref, $conf['expire'], $conf['cipher'], $conf['mode'], $conf['key']);
} else {
self::$_COOK[$cookref] = new cooky($cookref, $conf['expire'], FALSE);
}
}
return $cookref;
}
private static function getref($cookref){
if ( NULL === $cookref ){ //no args gived, we return default session handler
if ( FALSE !== ( $cookref = configs::get('cookies', 'Default')) ){
return $cookref;
} else {
return 'failsave';
}
} elseif ( is_array(configs::get('cookies', $cookref)) ){ return $cookref; }
return FALSE;
}
public static function isdefined($var, $cookref=NULL){
$cookref = self::load($cookref);
if ( FALSE === $cookref ){ return FALSE; }
return self::$_COOK[$cookref]->isdefined($var);
}
public static function read($var, $cookref=NULL){
$cookref = self::load($cookref);
if ( FALSE === $cookref ){ return FALSE; }
return self::$_COOK[$cookref]->read($var);
}
public static function set($var, $val, $cookref=NULL){
$cookref = self::load($cookref);
if ( FALSE === $cookref ){ return FALSE; }
return self::$_COOK[$cookref]->set($var, $val);
}
public static function del($var, $cookref=NULL){
$cookref = self::load($cookref);
if ( CORE::isError($cookref) ){ return $cookref; }
return self::$_COOK[$cookref]->del($var);
}
public static function clear($cookref=NULL){
$cookref = self::load($cookref);
if ( CORE::isError($cookref) ){ return $cookref; }
return self::$_COOK[$cookref]->clear();
}
}