Skip to content

Commit 426468f

Browse files
committed
Moving session work from unported to workbench; remove modularization in favor of php.js packaging style; remove session_update() in favor of $_SESSION(); note that tests will not pass as the code has not been fully adapted yet and it will need more features
1 parent 7653fcb commit 426468f

29 files changed

+216
-169
lines changed

_experimental/session/session_unregister.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

_unported/session/session.js

Lines changed: 0 additions & 92 deletions
This file was deleted.

_unported/session/session_decode.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

_unported/session/session_destroy.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

_unported/session/session_encode.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

_unported/session/session_set_cookie_params.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

_unported/session/session_start.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

_unported/session/session_unset.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

_workbench/session/$_SESSION.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function $_SESSION() {
2+
/**
3+
* Updates the session cookie data with $_SESSION
4+
*/
5+
var lifetime = 1800; //in seconds
6+
w.session_set_cookie('JSSESSID', w.serialize(w.$_SESSION), lifetime, path, domain, secure);
7+
}
8+
9+
function session_update() {
10+
this.setcookie('JSSESSID', this.serialize($_SESSION));
11+
}

_workbench/session/session_decode.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function session_decode(str) {
2+
/**
3+
* Decode string from session format
4+
*/
5+
return this.unserialize(this.urldecode(str));
6+
}

_workbench/session/session_destroy.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function session_destroy () {
2+
var t = this;
3+
4+
//* Bundle all session destroying functions (they all do the same thing)
5+
//* Resets the global $_SESSION and sets the cookie to null
6+
var session_set_cookie = function (name, value, expires, path, domain, secure) {
7+
if (expires) {
8+
expires = (new Date((new Date).getTime() + expires * 3600)).toGMTString();
9+
}
10+
11+
var r = [name + '=' + t.urlencode(value)], s = {}, i = '';
12+
s = {expires: expires, path: path, domain: domain};
13+
for (var i in s) {
14+
if (s.hasOwnProperty(i)) { // Exclude items on Object.prototype
15+
s[i] && r.push(i + '=' + s[i]);
16+
}
17+
}
18+
19+
return secure && r.push('secure'), document.cookie = r.join(";"), true;
20+
}
21+
22+
t.$_SESSION = null;
23+
// t.setcookie('JSSESSID', null);
24+
t.session_set_cookie('JSSESSID', null);
25+
}

_workbench/session/session_encode.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function session_encode () {
2+
/**
3+
* Encode string in session format (serialized then url encoded)
4+
*/
5+
return this.urldecode(this.getcookie('JSSESSID'));
6+
}
File renamed without changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Update the params of the cookie
3+
*/
4+
function session_set_cookie_params (l, p, d, s) {
5+
lifetime = l;
6+
path = p;
7+
domain = d;
8+
secure = !!s; //make sure bool
9+
}
10+
function session_set_cookie_params(lifetime, path, domain, secure) {
11+
12+
}

_workbench/session/session_start.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function session_start() {
2+
/**
3+
* Check for a PHPSESSID. If found unpack it from the cookie
4+
* If not found, create it then pack everything in $_SESSION
5+
* into a cookie.
6+
*/
7+
if(document.cookie.indexOf('JSSESSID=') === -1) {
8+
$_SESSION = {};
9+
this.setcookie('JSSESSID', this.serialize($_SESSION));
10+
} else {
11+
$_SESSION = this.unserialize(this.urldecode(this.getcookie('JSSESSID')));
12+
}
13+
}
14+
15+
/**
16+
* Check for a PHPSESSID. If found unpack it from the cookie
17+
* If not found, create it then pack everything in $_SESSION
18+
* into a cookie.
19+
*/
20+
function session_start () {
21+
function session_set_cookie (name, value, expires, path, domain, secure) {
22+
if (expires) {
23+
expires = (new Date((new Date).getTime() + expires * 3600)).toGMTString();
24+
}
25+
26+
var r = [name + '=' + w.urlencode(value)], s = {}, i = '';
27+
s = {expires: expires, path: path, domain: domain};
28+
for (i in s) {
29+
if (s.hasOwnProperty(i)) { // Exclude items on Object.prototype
30+
s[i] && r.push(i + '=' + s[i]);
31+
}
32+
}
33+
34+
return secure && r.push('secure'), w.document.cookie = r.join(";"), true;
35+
}
36+
37+
var sid = 'JSSESSID', t = this;
38+
var cookie = this.getcookie(sid);
39+
if(!cookie || cookie == "null") {
40+
t.$_SESSION = {};
41+
t.session_set_cookie(sid, t.serialize(t.$_SESSION), lifetime, path, domain, secure);
42+
} else {
43+
t.$_SESSION = t.unserialize(t.urldecode(t.getcookie(sid)));
44+
}
45+
}
46+
47+
48+
49+
function getcookie(name) {
50+
var cookies = document.cookie.split(';'),i=0,l=cookies.length,
51+
current;
52+
for(;i<l;i++) {
53+
current = cookies[i].split('=');
54+
if(current[0] === name) return current[1];
55+
}
56+
return undefined;
57+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function session_unregister (name) {
2+
// http://kevin.vanzonneveld.net
3+
// + original by: Brett Zamir (http://brett-zamir.me)
4+
// % note 1: Deprecated in PHP
5+
// * example 1: session_unregister('someVarName');
6+
// * returns 1: true
7+
8+
var obj = this.$_SESSION ? this : window; // Allow storage on the namespaced object
9+
if (obj.$_SESSION) {
10+
delete obj.$_SESSION[name];
11+
}
12+
return true;
13+
}
14+
15+
function session_unregister () {
16+
//* Bundle all session destroying functions (they all do the same thing)
17+
//* Resets the global $_SESSION and sets the cookie to null
18+
function session_set_cookie (name, value, expires, path, domain, secure) {
19+
if (expires) {
20+
expires = (new Date((new Date).getTime() + expires * 3600)).toGMTString();
21+
}
22+
23+
var r = [name + '=' + w.urlencode(value)], s = {}, i = '';
24+
s = {expires: expires, path: path, domain: domain};
25+
for (var i in s) {
26+
if (s.hasOwnProperty(i)) { // Exclude items on Object.prototype
27+
s[i] && r.push(i + '=' + s[i]);
28+
}
29+
}
30+
31+
return secure && r.push('secure'), w.document.cookie = r.join(";"), true;
32+
}
33+
34+
var t = this;
35+
t.$_SESSION = null;
36+
// t.setcookie('JSSESSID', null);
37+
t.session_set_cookie('JSSESSID', null);
38+
}

_workbench/session/session_unset.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function session_unset () {
2+
var t = this;
3+
//* Bundle all session destroying functions (they all do the same thing)
4+
//* Resets the global $_SESSION and sets the cookie to null
5+
var session_set_cookie = function (name, value, expires, path, domain, secure) {
6+
if (expires) {
7+
expires = (new Date((new Date).getTime() + expires * 3600)).toGMTString();
8+
}
9+
10+
var r = [name + '=' + t.urlencode(value)], s = {}, i = '';
11+
s = {expires: expires, path: path, domain: domain};
12+
for (var i in s) {
13+
if (s.hasOwnProperty(i)) { // Exclude items on Object.prototype
14+
s[i] && r.push(i + '=' + s[i]);
15+
}
16+
}
17+
18+
return secure && r.push('secure'), document.cookie = r.join(";"), true;
19+
}
20+
21+
t.$_SESSION = null;
22+
// t.setcookie('JSSESSID', null);
23+
t.session_set_cookie('JSSESSID', null);
24+
}

_workbench/session/session_utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Get value of a cookie
3+
*/
4+
function getcookie(name) {
5+
var cookies = document.cookie.split(';'),i=0,l=cookies.length,
6+
current;
7+
for(;i<l;i++) {
8+
current = cookies[i].split('=');
9+
// current[0] = current[0].replace(/\s+/,"");
10+
if(current[0] === name) {return current[1];}
11+
}
12+
return undefined;
13+
}

0 commit comments

Comments
 (0)