[20293] | 1 | <?php |
---|
| 2 | /*! |
---|
| 3 | * HybridAuth |
---|
| 4 | * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth |
---|
| 5 | * (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /** |
---|
| 9 | * HybridAuth storage manager |
---|
| 10 | */ |
---|
| 11 | class Hybrid_Storage |
---|
| 12 | { |
---|
| 13 | function __construct() |
---|
| 14 | { |
---|
| 15 | if ( ! session_id() ){ |
---|
| 16 | if( ! session_start() ){ |
---|
| 17 | throw new Exception( "Hybridauth requires the use of 'session_start()' at the start of your script, which appears to be disabled.", 1 ); |
---|
| 18 | } |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | $this->config( "php_session_id", session_id() ); |
---|
| 22 | $this->config( "version", Hybrid_Auth::$version ); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | public function config($key, $value=null) |
---|
| 26 | { |
---|
| 27 | $key = strtolower( $key ); |
---|
| 28 | |
---|
| 29 | if( $value ){ |
---|
| 30 | $_SESSION["HA::CONFIG"][$key] = $value; |
---|
| 31 | } |
---|
| 32 | elseif( isset( $_SESSION["HA::CONFIG"][$key] ) ){ |
---|
| 33 | return $_SESSION["HA::CONFIG"][$key]; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | return NULL; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | public function get($key) |
---|
| 40 | { |
---|
| 41 | $key = strtolower( $key ); |
---|
| 42 | |
---|
| 43 | if( isset( $_SESSION["HA::STORE"], $_SESSION["HA::STORE"][$key] ) ){ |
---|
| 44 | return $_SESSION["HA::STORE"][$key]; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | return NULL; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | public function set( $key, $value ) |
---|
| 51 | { |
---|
| 52 | $key = strtolower( $key ); |
---|
| 53 | |
---|
| 54 | $_SESSION["HA::STORE"][$key] = $value; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | function clear() |
---|
| 58 | { |
---|
| 59 | $_SESSION["HA::STORE"] = ARRAY(); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | function delete($key) |
---|
| 63 | { |
---|
| 64 | $key = strtolower( $key ); |
---|
| 65 | |
---|
| 66 | if( isset( $_SESSION["HA::STORE"], $_SESSION["HA::STORE"][$key] ) ){ |
---|
| 67 | unset( $_SESSION["HA::STORE"][$key] ); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function deleteMatch($key) |
---|
| 72 | { |
---|
| 73 | $key = strtolower( $key ); |
---|
| 74 | |
---|
| 75 | if( isset( $_SESSION["HA::STORE"] ) && count( $_SESSION["HA::STORE"] ) ) { |
---|
| 76 | foreach( $_SESSION["HA::STORE"] as $k => $v ){ |
---|
| 77 | if( strstr( $k, $key ) ){ |
---|
| 78 | unset( $_SESSION["HA::STORE"][ $k ] ); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | function getSessionData() |
---|
| 85 | { |
---|
| 86 | if( isset( $_SESSION["HA::STORE"] ) ){ |
---|
| 87 | return $_SESSION["HA::STORE"]; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | return NULL; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | function restoreSessionData( $sessiondata = NULL ) |
---|
| 94 | { |
---|
| 95 | $_SESSION["HA::STORE"] = $sessiondata; |
---|
| 96 | } |
---|
| 97 | } |
---|