Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

kcfinder\session class added #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@

);

?>
return $_CONFIG;
2 changes: 2 additions & 0 deletions core/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
require "core/class/browser.php";
elseif ($class == "minifier")
require "core/class/minifier.php";
elseif ($class == "session")
require "core/class/session.php";

elseif (file_exists("core/types/$class.php"))
require "core/types/$class.php";
Expand Down
94 changes: 94 additions & 0 deletions core/class/session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace kcfinder;

class session
{

const SESSION_VAR = '_sessionVar';

/** @var array */
private $config;

/** @var array|\Traversable */
private $session;

public function __construct(array $config)
{
$this->config = $config;
$this->initSession();
$this->initConfig();
}

/**
* @return array
*/
public function & getSession()
{
return $this->session;
}

/**
* @return array
*/
public function & getConfig()
{
return $this->config;
}

/***/
private function initSession()
{
if (isset($this->config[self::SESSION_VAR])) {
$session = & $this->config[self::SESSION_VAR];

if (!is_array($session) && !$session instanceof \Traversable) {
$session = $this->getDefaultSession()[$session];

if (!is_array($session)) {
$session = array();
}
}
} else {
$session = $this->getDefaultSession();
}

$this->session = & $session;
}

/**
* @return array
*/
private function & getDefaultSession()
{
// start default
if (!session_id()) {
if (isset($this->config['_sessionLifetime'])) {
ini_set('session.gc_maxlifetime', $this->config['_sessionLifetime'] * 60);
}

if (isset($this->config['_sessionDir'])) {
ini_set('session.save_path', $this->config['_sessionDir']);
}

if (isset($this->config['_sessionDomain'])) {
ini_set('session.cookie_domain', $this->config['_sessionDomain']);
}

session_start();
}

return $_SESSION;
}

/***/
private function initConfig()
{
foreach ($this->session as $key => $val) {
if ((substr($key, 0, 1) != "_") && isset($this->config[$key])) {
$this->config[$key] = $val;
}
}
}

}
43 changes: 5 additions & 38 deletions core/class/uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,45 +108,12 @@ public function __construct() {
$this->file = &$_FILES[key($_FILES)];

// LOAD DEFAULT CONFIGURATION
require "conf/config.php";

// SETTING UP SESSION
if (!session_id()) {
if (isset($_CONFIG['_sessionLifetime']))
ini_set('session.gc_maxlifetime', $_CONFIG['_sessionLifetime'] * 60);
if (isset($_CONFIG['_sessionDir']))
ini_set('session.save_path', $_CONFIG['_sessionDir']);
if (isset($_CONFIG['_sessionDomain']))
ini_set('session.cookie_domain', $_CONFIG['_sessionDomain']);
session_start();
}

// LOAD SESSION CONFIGURATION IF EXISTS
$this->config = $_CONFIG;
$sessVar = "_sessionVar";
if (isset($_CONFIG[$sessVar])) {

$sessVar = $_CONFIG[$sessVar];

if (!isset($_SESSION[$sessVar]))
$_SESSION[$sessVar] = array();

$sessVar = &$_SESSION[$sessVar];

if (!is_array($sessVar))
$sessVar = array();
$config = require "conf/config.php";

foreach ($sessVar as $key => $val)
if ((substr($key, 0, 1) != "_") && isset($_CONFIG[$key]))
$this->config[$key] = $val;

if (!isset($sessVar['self']))
$sessVar['self'] = array();

$this->session = &$sessVar['self'];

} else
$this->session = &$_SESSION;
// SETTING UP SESSION & CONFIG
$session = new session($config);
$this->session = $session->getSession();
$this->config = $session->getConfig();

// SECURING THE SESSION
$stamp = array(
Expand Down