.tmp
2 years ago
editors
2 years ago
libs
2 years ago
plugins
2 years ago
resources
2 years ago
MySQLStorage.sql
2 years ago
autoload.php
2 years ago
elFinder.class.php
2 years ago
elFinderConnector.class.php
2 years ago
elFinderFlysystemGoogleDriveNetmount.php
2 years ago
elFinderPlugin.php
2 years ago
elFinderSession.php
2 years ago
elFinderSessionInterface.php
2 years ago
elFinderVolumeBox.class.php
2 years ago
elFinderVolumeDriver.class.php
2 years ago
elFinderVolumeDropbox.class.php
2 years ago
elFinderVolumeDropbox2.class.php
2 years ago
elFinderVolumeFTP.class.php
2 years ago
elFinderVolumeGoogleDrive.class.php
2 years ago
elFinderVolumeGroup.class.php
2 years ago
elFinderVolumeLocalFileSystem.class.php
2 years ago
elFinderVolumeMySQL.class.php
2 years ago
elFinderVolumeOneDrive.class.php
2 years ago
elFinderVolumeSFTPphpseclib.class.php
2 years ago
elFinderVolumeTrash.class.php
2 years ago
elFinderVolumeTrashMySQL.class.php
2 years ago
index.php
2 years ago
mime.types
2 years ago
elFinderSession.php
248 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * elFinder - file manager for web. |
| 5 | * Session Wrapper Class. |
| 6 | * |
| 7 | * @package elfinder |
| 8 | * @author Naoki Sawada |
| 9 | **/ |
| 10 | |
| 11 | class elFinderSession implements elFinderSessionInterface |
| 12 | { |
| 13 | protected $started = false; |
| 14 | |
| 15 | protected $cookiePay = false; |
| 16 | |
| 17 | protected $keys = array(); |
| 18 | |
| 19 | protected $base64encode = false; |
| 20 | |
| 21 | protected $opts = array( |
| 22 | 'base64encode' => false, |
| 23 | 'keys' => array( |
| 24 | 'default' => 'elFinderCaches', |
| 25 | 'netvolume' => 'elFinderNetVolumes' |
| 26 | ) |
| 27 | ); |
| 28 | |
| 29 | public function __construct($opts) |
| 30 | { |
| 31 | $this->opts = array_merge($this->opts, $opts); |
| 32 | $this->base64encode = !empty($this->opts['base64encode']); |
| 33 | $this->keys = $this->opts['keys']; |
| 34 | |
| 35 | return $this; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * {@inheritdoc} |
| 40 | */ |
| 41 | public function start() |
| 42 | { |
| 43 | if (version_compare(PHP_VERSION, '5.4.0', '>=')) { |
| 44 | if (session_status() !== PHP_SESSION_ACTIVE) { |
| 45 | session_start(); |
| 46 | } |
| 47 | } else { |
| 48 | set_error_handler(array($this, 'session_start_error'), E_NOTICE); |
| 49 | session_start(); |
| 50 | restore_error_handler(); |
| 51 | } |
| 52 | $this->started = session_id() ? true : false; |
| 53 | |
| 54 | return $this; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * {@inheritdoc} |
| 59 | */ |
| 60 | public function close() |
| 61 | { |
| 62 | if ($this->started) { |
| 63 | if (!$this->cookiePay) { |
| 64 | $cParm = session_get_cookie_params(); |
| 65 | ini_set('session.use_cookies', 0); |
| 66 | setcookie(session_name(), session_id(), 0, $cParm['path'], $cParm['domain'], $cParm['secure'], $cParm['httponly']); |
| 67 | $this->cookiePay = true; |
| 68 | } |
| 69 | session_write_close(); |
| 70 | } |
| 71 | $this->started = false; |
| 72 | |
| 73 | return $this; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * {@inheritdoc} |
| 78 | */ |
| 79 | public function get($key, $empty = null) |
| 80 | { |
| 81 | $closed = false; |
| 82 | if (!$this->started) { |
| 83 | $closed = true; |
| 84 | $this->start(); |
| 85 | } |
| 86 | |
| 87 | $data = null; |
| 88 | |
| 89 | if ($this->started) { |
| 90 | $session =& $this->getSessionRef($key); |
| 91 | $data = $session; |
| 92 | if ($data && $this->base64encode) { |
| 93 | $data = $this->decodeData($data); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | $checkFn = null; |
| 98 | if (!is_null($empty)) { |
| 99 | if (is_string($empty)) { |
| 100 | $checkFn = 'is_string'; |
| 101 | } elseif (is_array($empty)) { |
| 102 | $checkFn = 'is_array'; |
| 103 | } elseif (is_object($empty)) { |
| 104 | $checkFn = 'is_object'; |
| 105 | } elseif (is_float($empty)) { |
| 106 | $checkFn = 'is_float'; |
| 107 | } elseif (is_int($empty)) { |
| 108 | $checkFn = 'is_int'; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (is_null($data) || ($checkFn && !$checkFn($data))) { |
| 113 | $session = $data = $empty; |
| 114 | } |
| 115 | |
| 116 | if ($closed) { |
| 117 | $this->close(); |
| 118 | } |
| 119 | |
| 120 | return $data; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * {@inheritdoc} |
| 125 | */ |
| 126 | public function set($key, $data) |
| 127 | { |
| 128 | $closed = false; |
| 129 | if (!$this->started) { |
| 130 | $closed = true; |
| 131 | $this->start(); |
| 132 | } |
| 133 | $session =& $this->getSessionRef($key); |
| 134 | if ($this->base64encode) { |
| 135 | $data = $this->encodeData($data); |
| 136 | } |
| 137 | $session = $data; |
| 138 | |
| 139 | if ($closed) { |
| 140 | $this->close(); |
| 141 | } |
| 142 | |
| 143 | return $this; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * {@inheritdoc} |
| 148 | */ |
| 149 | public function remove($key) |
| 150 | { |
| 151 | $closed = false; |
| 152 | if (!$this->started) { |
| 153 | $closed = true; |
| 154 | $this->start(); |
| 155 | } |
| 156 | |
| 157 | list($cat, $name) = array_pad(explode('.', $key, 2), 2, null); |
| 158 | if (is_null($name)) { |
| 159 | if (!isset($this->keys[$cat])) { |
| 160 | $name = $cat; |
| 161 | $cat = 'default'; |
| 162 | } |
| 163 | } |
| 164 | if (isset($this->keys[$cat])) { |
| 165 | $cat = $this->keys[$cat]; |
| 166 | } else { |
| 167 | $name = $cat . '.' . $name; |
| 168 | $cat = $this->keys['default']; |
| 169 | } |
| 170 | if (is_null($name)) { |
| 171 | unset($_SESSION[$cat]); |
| 172 | } else { |
| 173 | if (isset($_SESSION[$cat]) && is_array($_SESSION[$cat])) { |
| 174 | unset($_SESSION[$cat][$name]); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | if ($closed) { |
| 179 | $this->close(); |
| 180 | } |
| 181 | |
| 182 | return $this; |
| 183 | } |
| 184 | |
| 185 | protected function & getSessionRef($key) |
| 186 | { |
| 187 | $session = null; |
| 188 | if ($this->started) { |
| 189 | list($cat, $name) = array_pad(explode('.', $key, 2), 2, null); |
| 190 | if (is_null($name)) { |
| 191 | if (!isset($this->keys[$cat])) { |
| 192 | $name = $cat; |
| 193 | $cat = 'default'; |
| 194 | } |
| 195 | } |
| 196 | if (isset($this->keys[$cat])) { |
| 197 | $cat = $this->keys[$cat]; |
| 198 | } else { |
| 199 | $name = $cat . '.' . $name; |
| 200 | $cat = $this->keys['default']; |
| 201 | } |
| 202 | if (is_null($name)) { |
| 203 | if (!isset($_SESSION[$cat])) { |
| 204 | $_SESSION[$cat] = null; |
| 205 | } |
| 206 | $session =& $_SESSION[$cat]; |
| 207 | } else { |
| 208 | if (!isset($_SESSION[$cat]) || !is_array($_SESSION[$cat])) { |
| 209 | $_SESSION[$cat] = array(); |
| 210 | } |
| 211 | if (!isset($_SESSION[$cat][$name])) { |
| 212 | $_SESSION[$cat][$name] = null; |
| 213 | } |
| 214 | $session =& $_SESSION[$cat][$name]; |
| 215 | } |
| 216 | } |
| 217 | return $session; |
| 218 | } |
| 219 | |
| 220 | protected function encodeData($data) |
| 221 | { |
| 222 | if ($this->base64encode) { |
| 223 | $data = base64_encode(serialize($data)); |
| 224 | } |
| 225 | return $data; |
| 226 | } |
| 227 | |
| 228 | protected function decodeData($data) |
| 229 | { |
| 230 | if ($this->base64encode) { |
| 231 | if (is_string($data)) { |
| 232 | if (($data = base64_decode($data)) !== false) { |
| 233 | $data = unserialize($data); |
| 234 | } else { |
| 235 | $data = null; |
| 236 | } |
| 237 | } else { |
| 238 | $data = null; |
| 239 | } |
| 240 | } |
| 241 | return $data; |
| 242 | } |
| 243 | |
| 244 | protected function session_start_error($errno, $errstr) |
| 245 | { |
| 246 | } |
| 247 | } |
| 248 |