Permalink
Browse files

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
  • Loading branch information...
1 parent 7653fcb commit 426468f69906dda56b9e67ee28e828f2c24954a3 @brettz9 brettz9 committed Dec 4, 2010
Showing with 216 additions and 169 deletions.
  1. +0 −13 _experimental/session/session_unregister.js
  2. +0 −92 _unported/session/session.js
  3. +0 −3 _unported/session/session_decode.js
  4. +0 −3 _unported/session/session_destroy.js
  5. +0 −3 _unported/session/session_encode.js
  6. +0 −3 _unported/session/session_set_cookie_params.js
  7. +0 −27 _unported/session/session_start.js
  8. +0 −4 _unported/session/session_unset.js
  9. +11 −0 _workbench/session/$_SESSION.js
  10. 0 {_unported → _workbench}/session/php.default.min.js
  11. 0 {_experimental → _workbench}/session/session_commit.js
  12. +6 −0 _workbench/session/session_decode.js
  13. +25 −0 _workbench/session/session_destroy.js
  14. +6 −0 _workbench/session/session_encode.js
  15. 0 {_unported → _workbench}/session/session_get_cookie_params.js
  16. 0 {_unported → _workbench}/session/session_id.js
  17. 0 {_experimental → _workbench}/session/session_is_registered.js
  18. 0 {_unported → _workbench}/session/session_module_name.js
  19. 0 {_unported → _workbench}/session/session_name.js
  20. 0 {_unported → _workbench}/session/session_regenerate_id.js
  21. 0 {_experimental → _workbench}/session/session_register.js
  22. +12 −0 _workbench/session/session_set_cookie_params.js
  23. 0 {_unported → _workbench}/session/session_set_save_handler.js
  24. +57 −0 _workbench/session/session_start.js
  25. +38 −0 _workbench/session/session_unregister.js
  26. +24 −0 _workbench/session/session_unset.js
  27. +13 −0 _workbench/session/session_utils.js
  28. +23 −20 {_unported → _workbench}/session/test.html
  29. +1 −1 {_unported → _workbench}/session/test2.html
@@ -1,13 +0,0 @@
-function session_unregister (name) {
- // http://kevin.vanzonneveld.net
- // + original by: Brett Zamir (http://brett-zamir.me)
- // % note 1: Deprecated in PHP
- // * example 1: session_unregister('someVarName');
- // * returns 1: true
-
- var obj = this.$_SESSION ? this : window; // Allow storage on the namespaced object
- if (obj.$_SESSION) {
- delete obj.$_SESSION[name];
- }
- return true;
-}
@@ -1,92 +0,0 @@
-(function(w, undefined) {
- var lifetime = 1800, //in seconds
- path = undefined,
- domain = undefined,
- secure = undefined,
- sid = 'JSSESSID';
-
- /**
- * Check for a PHPSESSID. If found unpack it from the cookie
- * If not found, create it then pack everything in $_SESSION
- * into a cookie.
- */
- w.session_start = function() {
- var cookie = w.getcookie(sid);
- if(!cookie || cookie == "null") {
- w.$_SESSION = {};
- w.session_set_cookie(sid, w.serialize(w.$_SESSION), lifetime, path, domain, secure);
- } else {
- w.$_SESSION = w.unserialize(w.urldecode(w.getcookie(sid)));
- }
- };
-
- /**
- * Bundle all session destroying functions (they all do the same thing)
- * Resets the global $_SESSION and sets the cookie to null
- */
- w.session_unset = w.session_destroy = w.session_unregister = function() {
- w.$_SESSION = null;
- w.session_set_cookie(sid,null);
- };
-
- /**
- * Updates the session cookie data with $_SESSION
- */
- w.session_update = function() {
- w.session_set_cookie(sid, w.serialize(w.$_SESSION), lifetime, path, domain, secure);
- };
-
- /**
- * Update the params of the cookie
- */
- w.session_set_cookie_params = function(l, p, d, s) {
- lifetime = l;
- path = p;
- domain = d;
- secure = !!s; //make sure bool
- };
-
- /**
- * Get value of a cookie
- */
- w.getcookie = function(name) {
- var cookies = document.cookie.split(';'),i=0,l=cookies.length,
- current;
- for(;i<l;i++) {
- current = cookies[i].split('=');
- current[0] = current[0].replace(/\s+/,"");
- if(current[0] === name) return current[1];
- }
- return undefined;
- };
-
- w.session_set_cookie = function(name, value, expires, path, domain, secure) {
- if(expires) {
- expires = (new Date((new Date).getTime() + expires * 3600)).toGMTString();
- }
-
- var r = [name + '=' + w.urlencode(value)], s = {}, i = '';
- s = {expires: expires, path: path, domain: domain};
- for (i in s) {
- if (s.hasOwnProperty(i)) { // Exclude items on Object.prototype
- s[i] && r.push(i + '=' + s[i]);
- }
- }
-
- return secure && r.push('secure'), w.document.cookie = r.join(";"), true;
- }
-
- /**
- * Encode string in session format (serialized then url encoded)
- */
- w.session_encode = function() {
- return w.urldecode(w.getcookie(sid));
- }
-
- /**
- * Decode string from session format
- */
- w.session_decode = function(str) {
- return w.unserialize(w.urldecode(str));
- }
-})(window);
@@ -1,3 +0,0 @@
-function session_decode () {
-
-}
@@ -1,3 +0,0 @@
-function session_destroy () {
-
-}
@@ -1,3 +0,0 @@
-function session_encode () {
-
-}
@@ -1,3 +0,0 @@
-function session_set_cookie_params(lifetime, path, domain, secure) {
-
-}
@@ -1,27 +0,0 @@
-function session_start() {
- /**
- * Check for a PHPSESSID. If found unpack it from the cookie
- * If not found, create it then pack everything in $_SESSION
- * into a cookie.
- */
- if(document.cookie.indexOf('JSSESSID=') === -1) {
- $_SESSION = {};
- this.setcookie('JSSESSID', this.serialize($_SESSION));
- } else {
- $_SESSION = this.unserialize(urldecode(getcookie('JSSESSID')));
- }
-}
-
-function session_update() {
- this.setcookie('JSSESSID', this.serialize($_SESSION));
-}
-
-function getcookie(name) {
- var cookies = document.cookie.split(';'),i=0,l=cookies.length,
- current;
- for(;i<l;i++) {
- current = cookies[i].split('=');
- if(current[0] === name) return current[1];
- }
- return undefined;
-}
@@ -1,4 +0,0 @@
-function session_unset () {
- $_SESSION = {};
- this.setcookie('JSSESSID',null);
-}
@@ -0,0 +1,11 @@
+function $_SESSION() {
+ /**
+ * Updates the session cookie data with $_SESSION
+ */
+ var lifetime = 1800; //in seconds
+ w.session_set_cookie('JSSESSID', w.serialize(w.$_SESSION), lifetime, path, domain, secure);
+}
+
+function session_update() {
+ this.setcookie('JSSESSID', this.serialize($_SESSION));
+}
File renamed without changes.
@@ -0,0 +1,6 @@
+function session_decode(str) {
+/**
+* Decode string from session format
+*/
+ return this.unserialize(this.urldecode(str));
+}
@@ -0,0 +1,25 @@
+function session_destroy () {
+ var t = this;
+
+ //* Bundle all session destroying functions (they all do the same thing)
+ //* Resets the global $_SESSION and sets the cookie to null
+ var session_set_cookie = function (name, value, expires, path, domain, secure) {
+ if (expires) {
+ expires = (new Date((new Date).getTime() + expires * 3600)).toGMTString();
+ }
+
+ var r = [name + '=' + t.urlencode(value)], s = {}, i = '';
+ s = {expires: expires, path: path, domain: domain};
+ for (var i in s) {
+ if (s.hasOwnProperty(i)) { // Exclude items on Object.prototype
+ s[i] && r.push(i + '=' + s[i]);
+ }
+ }
+
+ return secure && r.push('secure'), document.cookie = r.join(";"), true;
+ }
+
+ t.$_SESSION = null;
+ // t.setcookie('JSSESSID', null);
+ t.session_set_cookie('JSSESSID', null);
+}
@@ -0,0 +1,6 @@
+function session_encode () {
+ /**
+ * Encode string in session format (serialized then url encoded)
+ */
+ return this.urldecode(this.getcookie('JSSESSID'));
+}
@@ -0,0 +1,12 @@
+/**
+ * Update the params of the cookie
+ */
+ function session_set_cookie_params (l, p, d, s) {
+ lifetime = l;
+ path = p;
+ domain = d;
+ secure = !!s; //make sure bool
+ }
+function session_set_cookie_params(lifetime, path, domain, secure) {
+
+}
@@ -0,0 +1,57 @@
+function session_start() {
+ /**
+ * Check for a PHPSESSID. If found unpack it from the cookie
+ * If not found, create it then pack everything in $_SESSION
+ * into a cookie.
+ */
+ if(document.cookie.indexOf('JSSESSID=') === -1) {
+ $_SESSION = {};
+ this.setcookie('JSSESSID', this.serialize($_SESSION));
+ } else {
+ $_SESSION = this.unserialize(this.urldecode(this.getcookie('JSSESSID')));
+ }
+}
+
+ /**
+ * Check for a PHPSESSID. If found unpack it from the cookie
+ * If not found, create it then pack everything in $_SESSION
+ * into a cookie.
+ */
+function session_start () {
+ function session_set_cookie (name, value, expires, path, domain, secure) {
+ if (expires) {
+ expires = (new Date((new Date).getTime() + expires * 3600)).toGMTString();
+ }
+
+ var r = [name + '=' + w.urlencode(value)], s = {}, i = '';
+ s = {expires: expires, path: path, domain: domain};
+ for (i in s) {
+ if (s.hasOwnProperty(i)) { // Exclude items on Object.prototype
+ s[i] && r.push(i + '=' + s[i]);
+ }
+ }
+
+ return secure && r.push('secure'), w.document.cookie = r.join(";"), true;
+ }
+
+ var sid = 'JSSESSID', t = this;
+ var cookie = this.getcookie(sid);
+ if(!cookie || cookie == "null") {
+ t.$_SESSION = {};
+ t.session_set_cookie(sid, t.serialize(t.$_SESSION), lifetime, path, domain, secure);
+ } else {
+ t.$_SESSION = t.unserialize(t.urldecode(t.getcookie(sid)));
+ }
+}
+
+
+
+function getcookie(name) {
+ var cookies = document.cookie.split(';'),i=0,l=cookies.length,
+ current;
+ for(;i<l;i++) {
+ current = cookies[i].split('=');
+ if(current[0] === name) return current[1];
+ }
+ return undefined;
+}
@@ -0,0 +1,38 @@
+function session_unregister (name) {
+ // http://kevin.vanzonneveld.net
+ // + original by: Brett Zamir (http://brett-zamir.me)
+ // % note 1: Deprecated in PHP
+ // * example 1: session_unregister('someVarName');
+ // * returns 1: true
+
+ var obj = this.$_SESSION ? this : window; // Allow storage on the namespaced object
+ if (obj.$_SESSION) {
+ delete obj.$_SESSION[name];
+ }
+ return true;
+}
+
+function session_unregister () {
+ //* Bundle all session destroying functions (they all do the same thing)
+ //* Resets the global $_SESSION and sets the cookie to null
+ function session_set_cookie (name, value, expires, path, domain, secure) {
+ if (expires) {
+ expires = (new Date((new Date).getTime() + expires * 3600)).toGMTString();
+ }
+
+ var r = [name + '=' + w.urlencode(value)], s = {}, i = '';
+ s = {expires: expires, path: path, domain: domain};
+ for (var i in s) {
+ if (s.hasOwnProperty(i)) { // Exclude items on Object.prototype
+ s[i] && r.push(i + '=' + s[i]);
+ }
+ }
+
+ return secure && r.push('secure'), w.document.cookie = r.join(";"), true;
+ }
+
+ var t = this;
+ t.$_SESSION = null;
+ // t.setcookie('JSSESSID', null);
+ t.session_set_cookie('JSSESSID', null);
+}
@@ -0,0 +1,24 @@
+function session_unset () {
+ var t = this;
+ //* Bundle all session destroying functions (they all do the same thing)
+ //* Resets the global $_SESSION and sets the cookie to null
+ var session_set_cookie = function (name, value, expires, path, domain, secure) {
+ if (expires) {
+ expires = (new Date((new Date).getTime() + expires * 3600)).toGMTString();
+ }
+
+ var r = [name + '=' + t.urlencode(value)], s = {}, i = '';
+ s = {expires: expires, path: path, domain: domain};
+ for (var i in s) {
+ if (s.hasOwnProperty(i)) { // Exclude items on Object.prototype
+ s[i] && r.push(i + '=' + s[i]);
+ }
+ }
+
+ return secure && r.push('secure'), document.cookie = r.join(";"), true;
+ }
+
+ t.$_SESSION = null;
+ // t.setcookie('JSSESSID', null);
+ t.session_set_cookie('JSSESSID', null);
+}
@@ -0,0 +1,13 @@
+/**
+* Get value of a cookie
+*/
+function getcookie(name) {
+ var cookies = document.cookie.split(';'),i=0,l=cookies.length,
+ current;
+ for(;i<l;i++) {
+ current = cookies[i].split('=');
+// current[0] = current[0].replace(/\s+/,"");
+ if(current[0] === name) {return current[1];}
+ }
+ return undefined;
+}
Oops, something went wrong. Retry.

0 comments on commit 426468f

Please sign in to comment.