diff --git a/ext/chatbox/cp/ajax.php b/ext/chatbox/cp/ajax.php new file mode 100644 index 00000000..adc757ce --- /dev/null +++ b/ext/chatbox/cp/ajax.php @@ -0,0 +1,459 @@ + +error_reporting(E_ALL); +$kioskMode = false; + +include '../php/filestorage.class.php'; +include '../preferences.php'; +include '../php/json.class.php'; +include '../php/functions.php'; +include '../php/yshout.class.php'; +include '../php/ajaxcall.class.php'; + +if (isset($_POST['mode'])) + switch($_POST['mode']) { + case 'login': + doLogin(); + break; + case 'logout': + doLogout(); + break; + case 'unban': + doUnban(); + break; + case 'unbanall': + doUnbanAll(); + break; + case 'setpreference': + doSetPreference(); + break; + case 'resetpreferences': + doResetPreferences(); + break; + } + +function doLogin() { + global $kioskMode; + + if ($kioskMode) { + logout(); + $result = array( + 'error' => false, + 'html' => cp() + ); + + echo jsonEncode($result); + return; + } + + login(md5($_POST['password'])); + $result = array(); + if (loggedIn()) { + $result['error'] = false; + $result['html'] = cp(); + } else + $result['error'] = 'invalid'; + + echo jsonEncode($result); +} + +function doLogout() { + logout(); + + $result = array( + 'error' => false + ); + + echo jsonEncode($result); +} + +function doUnban() { + global $kioskMode; + + if ($kioskMode) { + $result = array( + 'error' => false + ); + + echo jsonEncode($result); + return; + } + + if (!loggedIn()) return; + + $ys = ys(); + $result = array(); + + $ip = $_POST['ip']; + + if ($ys->banned($ip)) { + $ys->unban($ip); + $result['error'] = false; + } else + $result['error'] = 'notbanned'; + + + echo jsonEncode($result); +} + +function doUnbanAll() { + global $kioskMode; + + if ($kioskMode) { + $result = array( + 'error' => false + ); + + echo jsonEncode($result); + return; + } + + if (!loggedIn()) return; + + $ys = ys(); + $ys->unbanAll(); + + $result = array( + 'error' => false + ); + + echo jsonEncode($result); +} + + +function doSetPreference() { + global $prefs, $kioskMode; + + if ($kioskMode) { + $result = array( + 'error' => false + ); + + echo jsonEncode($result); + return; + } + + if (!loggedIn()) return; + + $pref = $_POST['preference']; + $value = magic($_POST['value']); + + if ($value === 'true') $value = true; + if ($value === 'false') $value = false; + + $prefs[$pref] = $value; + + savePrefs($prefs); + + if ($pref == 'password') login(md5($value)); + + $result = array( + 'error' => false + ); + + echo jsonEncode($result); +} + + +function doResetPreferences() { + global $prefs, $kioskMode; + + if ($kioskMode) { + $result = array( + 'error' => false + ); + + echo jsonEncode($result); + return; + } + + if (!loggedIn()) return; + + resetPrefs(); + login(md5($prefs['password'])); + + // $prefs['password'] = 'lol no'; + $result = array( + 'error' => false, + 'prefs' => $prefs + ); + + echo jsonEncode($result); +} + +/* CP Display */ + +function cp() { + global $kioskMode; + + if (!loggedIn() && !$kioskMode) return 'You\'re not logged in!'; + + return ' + +
No one is banned.
'; + else + $html .= 'YShout was created and developed by Yuri Vishnevsky. Version 5 is the first one with an about page, so you\'ll have to excuse the lack of appropriate information — I\'m not quite sure what it is that goes on "About" pages anyway.
+Other than that obviously important tidbit of information, there\'s really nothing else that I can think of putting here... If anyone knows what a good and proper about page should contain, please contact me! +
If you have any questions or comments, you can contact me by email at yurivish@gmail.com, or on AIM at yurivish42.
+I hope you\'ve enjoyed using YShout!
+=0))l||m.push(v);else if(l)h[p]=false;return false},ID:function(g){return g[1].replace(/\\/g,"")},TAG:function(g){return g[1].toLowerCase()}, +CHILD:function(g){if(g[1]==="nth"){var h=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(g[2]==="even"&&"2n"||g[2]==="odd"&&"2n+1"||!/\D/.test(g[2])&&"0n+"+g[2]||g[2]);g[2]=h[1]+(h[2]||1)-0;g[3]=h[3]-0}g[0]=e++;return g},ATTR:function(g,h,l,m,q,p){h=g[1].replace(/\\/g,"");if(!p&&n.attrMap[h])g[1]=n.attrMap[h];if(g[2]==="~=")g[4]=" "+g[4]+" ";return g},PSEUDO:function(g,h,l,m,q){if(g[1]==="not")if((f.exec(g[3])||"").length>1||/^\w/.test(g[3]))g[3]=k(g[3],null,null,h);else{g=k.filter(g[3],h,l,true^q);l||m.push.apply(m, +g);return false}else if(n.match.POS.test(g[0])||n.match.CHILD.test(g[0]))return true;return g},POS:function(g){g.unshift(true);return g}},filters:{enabled:function(g){return g.disabled===false&&g.type!=="hidden"},disabled:function(g){return g.disabled===true},checked:function(g){return g.checked===true},selected:function(g){return g.selected===true},parent:function(g){return!!g.firstChild},empty:function(g){return!g.firstChild},has:function(g,h,l){return!!k(l[3],g).length},header:function(g){return/h\d/i.test(g.nodeName)}, +text:function(g){return"text"===g.type},radio:function(g){return"radio"===g.type},checkbox:function(g){return"checkbox"===g.type},file:function(g){return"file"===g.type},password:function(g){return"password"===g.type},submit:function(g){return"submit"===g.type},image:function(g){return"image"===g.type},reset:function(g){return"reset"===g.type},button:function(g){return"button"===g.type||g.nodeName.toLowerCase()==="button"},input:function(g){return/input|select|textarea|button/i.test(g.nodeName)}}, +setFilters:{first:function(g,h){return h===0},last:function(g,h,l,m){return h===m.length-1},even:function(g,h){return h%2===0},odd:function(g,h){return h%2===1},lt:function(g,h,l){return hl[3]-0},nth:function(g,h,l){return l[3]-0===h},eq:function(g,h,l){return l[3]-0===h}},filter:{PSEUDO:function(g,h,l,m){var q=h[1],p=n.filters[q];if(p)return p(g,l,h,m);else if(q==="contains")return(g.textContent||g.innerText||a([g])||"").indexOf(h[3])>=0;else if(q==="not"){h= +h[3];l=0;for(m=h.length;l =0}},ID:function(g,h){return g.nodeType===1&&g.getAttribute("id")===h},TAG:function(g,h){return h==="*"&&g.nodeType===1||g.nodeName.toLowerCase()===h},CLASS:function(g,h){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(h)>-1},ATTR:function(g,h){var l=h[1];g=n.attrHandle[l]?n.attrHandle[l](g):g[l]!=null?g[l]:g.getAttribute(l);l=g+"";var m=h[2];h=h[4];return g==null?m==="!=":m=== +"="?l===h:m==="*="?l.indexOf(h)>=0:m==="~="?(" "+l+" ").indexOf(h)>=0:!h?l&&g!==false:m==="!="?l!==h:m==="^="?l.indexOf(h)===0:m==="$="?l.substr(l.length-h.length)===h:m==="|="?l===h||l.substr(0,h.length+1)===h+"-":false},POS:function(g,h,l,m){var q=n.setFilters[h[2]];if(q)return q(g,l,h,m)}}},r=n.match.POS;for(var u in n.match){n.match[u]=new RegExp(n.match[u].source+/(?![^\[]*\])(?![^\(]*\))/.source);n.leftMatch[u]=new RegExp(/(^(?:.|\r|\n)*?)/.source+n.match[u].source.replace(/\\(\d+)/g,function(g, +h){return"\\"+(h-0+1)}))}var z=function(g,h){g=Array.prototype.slice.call(g,0);if(h){h.push.apply(h,g);return h}return g};try{Array.prototype.slice.call(s.documentElement.childNodes,0)}catch(C){z=function(g,h){h=h||[];if(j.call(g)==="[object Array]")Array.prototype.push.apply(h,g);else if(typeof g.length==="number")for(var l=0,m=g.length;l ";var l=s.documentElement;l.insertBefore(g,l.firstChild);if(s.getElementById(h)){n.find.ID=function(m,q,p){if(typeof q.getElementById!=="undefined"&&!p)return(q=q.getElementById(m[1]))?q.id===m[1]||typeof q.getAttributeNode!=="undefined"&& +q.getAttributeNode("id").nodeValue===m[1]?[q]:w:[]};n.filter.ID=function(m,q){var p=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&p&&p.nodeValue===q}}l.removeChild(g);l=g=null})();(function(){var g=s.createElement("div");g.appendChild(s.createComment(""));if(g.getElementsByTagName("*").length>0)n.find.TAG=function(h,l){l=l.getElementsByTagName(h[1]);if(h[1]==="*"){h=[];for(var m=0;l[m];m++)l[m].nodeType===1&&h.push(l[m]);l=h}return l};g.innerHTML=""; +if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")n.attrHandle.href=function(h){return h.getAttribute("href",2)};g=null})();s.querySelectorAll&&function(){var g=k,h=s.createElement("div");h.innerHTML="";if(!(h.querySelectorAll&&h.querySelectorAll(".TEST").length===0)){k=function(m,q,p,v){q=q||s;if(!v&&q.nodeType===9&&!x(q))try{return z(q.querySelectorAll(m),p)}catch(t){}return g(m,q,p,v)};for(var l in g)k[l]=g[l];h=null}}(); +(function(){var g=s.createElement("div");g.innerHTML="";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length===0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){n.order.splice(1,0,"CLASS");n.find.CLASS=function(h,l,m){if(typeof l.getElementsByClassName!=="undefined"&&!m)return l.getElementsByClassName(h[1])};g=null}}})();var E=s.compareDocumentPosition?function(g,h){return!!(g.compareDocumentPosition(h)&16)}: +function(g,h){return g!==h&&(g.contains?g.contains(h):true)},x=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false},ga=function(g,h){var l=[],m="",q;for(h=h.nodeType?[h]:h;q=n.match.PSEUDO.exec(g);){m+=q[0];g=g.replace(n.match.PSEUDO,"")}g=n.relative[g]?g+"*":g;q=0;for(var p=h.length;q =0===d})};c.fn.extend({find:function(a){for(var b=this.pushStack("","find",a),d=0,f=0,e=this.length;f
0)for(var j=d;j 0},closest:function(a,b){if(c.isArray(a)){var d=[],f=this[0],e,j= +{},i;if(f&&a.length){e=0;for(var o=a.length;e -1:c(f).is(e)){d.push({selector:i,elem:f});delete j[i]}}f=f.parentNode}}return d}var k=c.expr.match.POS.test(a)?c(a,b||this.context):null;return this.map(function(n,r){for(;r&&r.ownerDocument&&r!==b;){if(k?k.index(r)>-1:c(r).is(a))return r;r=r.parentNode}return null})},index:function(a){if(!a||typeof a=== +"string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){a=typeof a==="string"?c(a,b||this.context):c.makeArray(a);b=c.merge(this.get(),a);return this.pushStack(qa(a[0])||qa(b[0])?b:c.unique(b))},andSelf:function(){return this.add(this.prevObject)}});c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode", +d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling",d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")? +a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,b){c.fn[a]=function(d,f){var e=c.map(this,b,d);eb.test(a)||(f=d);if(f&&typeof f==="string")e=c.filter(f,e);e=this.length>1?c.unique(e):e;if((this.length>1||gb.test(f))&&fb.test(a))e=e.reverse();return this.pushStack(e,a,R.call(arguments).join(","))}});c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return c.find.matches(a,b)},dir:function(a,b,d){var f=[];for(a=a[b];a&&a.nodeType!==9&&(d===w||a.nodeType!==1||!c(a).is(d));){a.nodeType=== +1&&f.push(a);a=a[b]}return f},nth:function(a,b,d){b=b||1;for(var f=0;a;a=a[d])if(a.nodeType===1&&++f===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var Ja=/ jQuery\d+="(?:\d+|null)"/g,V=/^\s+/,Ka=/(<([\w:]+)[^>]*?)\/>/g,hb=/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,La=/<([\w:]+)/,ib=/"+d+">"},F={option:[1,""],legend:[1,""],thead:[1," ","
"],tr:[2,"","
"],td:[3,""],col:[2,"
"," "],area:[1,""],_default:[0,"",""]};F.optgroup=F.option;F.tbody=F.tfoot=F.colgroup=F.caption=F.thead;F.th=F.td;if(!c.support.htmlSerialize)F._default=[1,"div
"," ",""];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d= +c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==w)return this.empty().append((this[0]&&this[0].ownerDocument||s).createTextNode(a));return c.text(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this,d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this}, +wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})}, +prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a=c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b, +this.nextSibling)});else if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},remove:function(a,b){for(var d=0,f;(f=this[d])!=null;d++)if(!a||c.filter(a,[f]).length){if(!b&&f.nodeType===1){c.cleanData(f.getElementsByTagName("*"));c.cleanData([f])}f.parentNode&&f.parentNode.removeChild(f)}return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++)for(b.nodeType===1&&c.cleanData(b.getElementsByTagName("*"));b.firstChild;)b.removeChild(b.firstChild); +return this},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,f=this.ownerDocument;if(!d){d=f.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(Ja,"").replace(/=([^="'>\s]+\/)>/g,'="$1">').replace(V,"")],f)[0]}else return this.cloneNode(true)});if(a===true){ra(this,b);ra(this.find("*"),b.find("*"))}return b},html:function(a){if(a===w)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(Ja, +""):null;else if(typeof a==="string"&&!ta.test(a)&&(c.support.leadingWhitespace||!V.test(a))&&!F[(La.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Ka,Ma);try{for(var b=0,d=this.length;b0||e.cacheable||this.length>1?k.cloneNode(true):k)}o.length&&c.each(o,Qa)}return this}});c.fragments={};c.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){c.fn[a]=function(d){var f=[];d=c(d);var e=this.length===1&&this[0].parentNode;if(e&&e.nodeType===11&&e.childNodes.length===1&&d.length===1){d[b](this[0]); +return this}else{e=0;for(var j=d.length;e 0?this.clone(true):this).get();c.fn[b].apply(c(d[e]),i);f=f.concat(i)}return this.pushStack(f,a,d.selector)}}});c.extend({clean:function(a,b,d,f){b=b||s;if(typeof b.createElement==="undefined")b=b.ownerDocument||b[0]&&b[0].ownerDocument||s;for(var e=[],j=0,i;(i=a[j])!=null;j++){if(typeof i==="number")i+="";if(i){if(typeof i==="string"&&!jb.test(i))i=b.createTextNode(i);else if(typeof i==="string"){i=i.replace(Ka,Ma);var o=(La.exec(i)||["", +""])[1].toLowerCase(),k=F[o]||F._default,n=k[0],r=b.createElement("div");for(r.innerHTML=k[1]+i+k[2];n--;)r=r.lastChild;if(!c.support.tbody){n=ib.test(i);o=o==="table"&&!n?r.firstChild&&r.firstChild.childNodes:k[1]===" "&&!n?r.childNodes:[];for(k=o.length-1;k>=0;--k)c.nodeName(o[k],"tbody")&&!o[k].childNodes.length&&o[k].parentNode.removeChild(o[k])}!c.support.leadingWhitespace&&V.test(i)&&r.insertBefore(b.createTextNode(V.exec(i)[0]),r.firstChild);i=r.childNodes}if(i.nodeType)e.push(i);else e= +c.merge(e,i)}}if(d)for(j=0;e[j];j++)if(f&&c.nodeName(e[j],"script")&&(!e[j].type||e[j].type.toLowerCase()==="text/javascript"))f.push(e[j].parentNode?e[j].parentNode.removeChild(e[j]):e[j]);else{e[j].nodeType===1&&e.splice.apply(e,[j+1,0].concat(c.makeArray(e[j].getElementsByTagName("script"))));d.appendChild(e[j])}return e},cleanData:function(a){for(var b,d,f=c.cache,e=c.event.special,j=c.support.deleteExpando,i=0,o;(o=a[i])!=null;i++)if(d=o[c.expando]){b=f[d];if(b.events)for(var k in b.events)e[k]? +c.event.remove(o,k):Ca(o,k,b.handle);if(j)delete o[c.expando];else o.removeAttribute&&o.removeAttribute(c.expando);delete f[d]}}});var kb=/z-?index|font-?weight|opacity|zoom|line-?height/i,Na=/alpha\([^)]*\)/,Oa=/opacity=([^)]*)/,ha=/float/i,ia=/-([a-z])/ig,lb=/([A-Z])/g,mb=/^-?\d+(?:px)?$/i,nb=/^-?\d/,ob={position:"absolute",visibility:"hidden",display:"block"},pb=["Left","Right"],qb=["Top","Bottom"],rb=s.defaultView&&s.defaultView.getComputedStyle,Pa=c.support.cssFloat?"cssFloat":"styleFloat",ja= +function(a,b){return b.toUpperCase()};c.fn.css=function(a,b){return X(this,a,b,true,function(d,f,e){if(e===w)return c.curCSS(d,f);if(typeof e==="number"&&!kb.test(f))e+="px";c.style(d,f,e)})};c.extend({style:function(a,b,d){if(!a||a.nodeType===3||a.nodeType===8)return w;if((b==="width"||b==="height")&&parseFloat(d)<0)d=w;var f=a.style||a,e=d!==w;if(!c.support.opacity&&b==="opacity"){if(e){f.zoom=1;b=parseInt(d,10)+""==="NaN"?"":"alpha(opacity="+d*100+")";a=f.filter||c.curCSS(a,"filter")||"";f.filter= +Na.test(a)?a.replace(Na,b):b}return f.filter&&f.filter.indexOf("opacity=")>=0?parseFloat(Oa.exec(f.filter)[1])/100+"":""}if(ha.test(b))b=Pa;b=b.replace(ia,ja);if(e)f[b]=d;return f[b]},css:function(a,b,d,f){if(b==="width"||b==="height"){var e,j=b==="width"?pb:qb;function i(){e=b==="width"?a.offsetWidth:a.offsetHeight;f!=="border"&&c.each(j,function(){f||(e-=parseFloat(c.curCSS(a,"padding"+this,true))||0);if(f==="margin")e+=parseFloat(c.curCSS(a,"margin"+this,true))||0;else e-=parseFloat(c.curCSS(a, +"border"+this+"Width",true))||0})}a.offsetWidth!==0?i():c.swap(a,ob,i);return Math.max(0,Math.round(e))}return c.curCSS(a,b,d)},curCSS:function(a,b,d){var f,e=a.style;if(!c.support.opacity&&b==="opacity"&&a.currentStyle){f=Oa.test(a.currentStyle.filter||"")?parseFloat(RegExp.$1)/100+"":"";return f===""?"1":f}if(ha.test(b))b=Pa;if(!d&&e&&e[b])f=e[b];else if(rb){if(ha.test(b))b="float";b=b.replace(lb,"-$1").toLowerCase();e=a.ownerDocument.defaultView;if(!e)return null;if(a=e.getComputedStyle(a,null))f= +a.getPropertyValue(b);if(b==="opacity"&&f==="")f="1"}else if(a.currentStyle){d=b.replace(ia,ja);f=a.currentStyle[b]||a.currentStyle[d];if(!mb.test(f)&&nb.test(f)){b=e.left;var j=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;e.left=d==="fontSize"?"1em":f||0;f=e.pixelLeft+"px";e.left=b;a.runtimeStyle.left=j}}return f},swap:function(a,b,d){var f={};for(var e in b){f[e]=a.style[e];a.style[e]=b[e]}d.call(a);for(e in b)a.style[e]=f[e]}});if(c.expr&&c.expr.filters){c.expr.filters.hidden=function(a){var b= +a.offsetWidth,d=a.offsetHeight,f=a.nodeName.toLowerCase()==="tr";return b===0&&d===0&&!f?true:b>0&&d>0&&!f?false:c.curCSS(a,"display")==="none"};c.expr.filters.visible=function(a){return!c.expr.filters.hidden(a)}}var sb=J(),tb=/ + + + + + + "); + + // loads the chatbox at the set location + $html = ""; + $chatblock = new Block("Chatbox", $html, "main", 97); + $page->add_block($chatblock); + } +} +?> diff --git a/ext/chatbox/php/ajaxcall.class.php b/ext/chatbox/php/ajaxcall.class.php new file mode 100644 index 00000000..6753830d --- /dev/null +++ b/ext/chatbox/php/ajaxcall.class.php @@ -0,0 +1,279 @@ + + class AjaxCall { + function AjaxCall($log = null) { + header('Content-type: application/json'); + session_start(); + + if (isset($log)) $_SESSION['yLog'] = $log; + + $this->reqType = $_POST['reqType']; + } + + function process() { + switch($this->reqType) { + case 'init': + + $this->initSession(); + $this->sendFirstUpdates(); + break; + + case 'post': + $nickname = $_POST['nickname']; + $message = $_POST['message']; + cookie('yNickname', $nickname); + $ys = ys($_SESSION['yLog']); + + if ($ys->banned(ip())) { $this->sendBanned(); break; } + if ($post = $ys->post($nickname, $message)) // To use $post somewheres later + $this->sendUpdates(); + break; + + case 'refresh': + $ys = ys($_SESSION['yLog']); + if ($ys->banned(ip())) { $this->sendBanned(); break; } + + $this->sendUpdates(); + break; + + case 'reload': + $this->reload(); + break; + + case 'ban': + $this->doBan(); + break; + + case 'unban': + $this->doUnban(); + break; + + case 'delete': + $this->doDelete(); + break; + + case 'banself': + $this->banSelf(); + break; + + case 'unbanself': + $this->unbanSelf(); + break; + + case 'clearlog': + $this->clearLog(); + break; + + case 'clearlogs': + $this->clearLogs(); + break; + } + } + + function doBan() { + $ip = $_POST['ip']; + $nickname = $_POST['nickname']; + $send = array(); + $ys = ys($_SESSION['yLog']); + + switch(true) { + case !loggedIn(): + $send['error'] = 'admin'; + break; + case $ys->banned($ip): + $send['error'] = 'already'; + break; + default: + $ys->ban($ip, $nickname); + if ($ip == ip()) + $send['bannedSelf'] = true; + $send['error'] = false; + } + + echo jsonEncode($send); + } + + function doUnban() { + $ip = $_POST['ip']; + $send = array(); + $ys = ys($_SESSION['yLog']); + + switch(true) { + case !loggedIn(): + $send['error'] = 'admin'; + break; + case !$ys->banned($ip): + $send['error'] = 'already'; + break; + default: + $ys->unban($ip); + $send['error'] = false; + } + + echo jsonEncode($send); + } + + function doDelete() { + $uid = $_POST['uid']; + $send = array(); + $ys = ys($_SESSION['yLog']); + + switch(true) { + case !loggedIn(): + $send['error'] = 'admin'; + break; + default: + $ys->delete($uid); + $send['error'] = false; + } + + echo jsonEncode($send); + } + + function banSelf() { + $ys = ys($_SESSION['yLog']); + $nickname = $_POST['nickname']; + $ys->ban(ip(), $nickname); + + $send = array(); + $send['error'] = false; + + echo jsonEncode($send); + + } + + function unbanSelf() { + if (loggedIn()) { + $ys = ys($_SESSION['yLog']); + $ys->unban(ip()); + + $send = array(); + $send['error'] = false; + } else { + $send = array(); + $send['error'] = 'admin'; + } + + echo jsonEncode($send); + } + + function reload() { + global $prefs; + $ys = ys($_SESSION['yLog']); + + $posts = $ys->latestPosts($prefs['truncate']); + $this->setSessTimestamp($posts); + $this->updates['posts'] = $posts; + echo jsonEncode($this->updates); + } + + function initSession() { + $_SESSION['yLatestTimestamp'] = 0; + $_SESSION['yYPath'] = $_POST['yPath']; + $_SESSION['yLog'] = $_POST['log']; + $loginHash = cookieGet('yLoginHash') ; + if (isset($loginHash) && $loginHash != '') { + login($loginHash); + } + } + + function sendBanned() { + $this->updates = array( + 'banned' => true + ); + + echo jsonEncode($this->updates); + } + + function sendUpdates() { + global $prefs; + $ys = ys($_SESSION['yLog']); + if (!$ys->hasPostsAfter($_SESSION['yLatestTimestamp'])) return; + + $posts = $ys->postsAfter($_SESSION['yLatestTimestamp']); + $this->setSessTimestamp($posts); + + $this->updates['posts'] = $posts; + + echo jsonEncode($this->updates); + } + + function setSessTimestamp(&$posts) { + if (!$posts) return; + + $latest = array_slice( $posts, -1, 1); + $_SESSION['yLatestTimestamp'] = $latest[0]['timestamp']; + } + + function sendFirstUpdates() { + global $prefs, $overrideNickname; + + $this->updates = array(); + + $ys = ys($_SESSION['yLog']); + + $posts = $ys->latestPosts($prefs['truncate']); + $this->setSessTimestamp($posts); + + $this->updates['posts'] = $posts; + $this->updates['prefs'] = $this->cleanPrefs($prefs); + + if ($nickname = cookieGet('yNickname')) + $this->updates['nickname'] = $nickname; + + if ($overrideNickname) + $this->updates['nickname'] = $overrideNickname; + + if ($ys->banned(ip())) + $this->updates['banned'] = true; + + echo jsonEncode($this->updates); + } + + function cleanPrefs($prefs) { + unset($prefs['password']); + return $prefs; + } + + function clearLog() { + $log = $_POST['log']; + $send = array(); + $ys = ys($_SESSION['yLog']); + + switch(true) { + case !loggedIn(): + $send['error'] = 'admin'; + break; + default: + $ys->clear(); + $send['error'] = false; + } + + echo jsonEncode($send); + } + + function clearLogs() { + global $prefs; + + $log = $_POST['log']; + $send = array(); + + $ys = ys($_SESSION['yLog']); + + switch(true) { + case !loggedIn(): + $send['error'] = 'admin'; + break; + default: + for ($i = 1; $i <= $prefs['logs']; $i++) { + $ys = ys($i); + $ys->clear(); + } + + $send['error'] = false; + } + + echo jsonEncode($send); + } + } + +?> \ No newline at end of file diff --git a/ext/chatbox/php/filestorage.class.php b/ext/chatbox/php/filestorage.class.php new file mode 100644 index 00000000..ac462111 --- /dev/null +++ b/ext/chatbox/php/filestorage.class.php @@ -0,0 +1,85 @@ + + +class FileStorage { + + function FileStorage($path, $shoutLog = false) { + $this->shoutLog = $shoutLog; + $folder = 'logs'; + if (!is_dir($folder)) $folder = '../' . $folder; + if (!is_dir($folder)) $folder = '../' . $folder; + + $this->path = $folder . '/' . $path . '.txt'; + } + + function open($lock = false) { + $this->handle = fopen($this->path, 'a+'); + + if ($lock) { + $this->lock(); + return $this->load(); + } + } + + function close(&$array) { + if (isset($array)) + $this->save($array); + + $this->unlock(); + fclose($this->handle); + unset($this->handle); + } + + function load() { + if (($contents = $this->read($this->path)) == null) + return $this->resetArray(); + + return unserialize($contents); + } + + function save(&$array, $unlock = true) { + $contents = serialize($array); + $this->write($contents); + if ($unlock) $this->unlock(); + } + + function unlock() { + if (isset($this->handle)) + flock($this->handle, LOCK_UN); + } + + function lock() { + if (isset($this->handle)) + flock($this->handle, LOCK_EX); + } + + function read() { + fseek($this->handle, 0); + //return stream_get_contents($this->handle); + return file_get_contents($this->path); + + } + + function write($contents) { + ftruncate($this->handle, 0); + fwrite($this->handle, $contents); + } + + function resetArray() { + if ($this->shoutLog) + $default = array( + 'info' => array( + 'latestTimestamp' => -1 + ), + + 'posts' => array() + ); + else + $default = array(); + + $this->save($default, false); + return $default; + } + +} + +?> \ No newline at end of file diff --git a/ext/chatbox/php/functions.php b/ext/chatbox/php/functions.php new file mode 100644 index 00000000..edfd521f --- /dev/null +++ b/ext/chatbox/php/functions.php @@ -0,0 +1,152 @@ + + + function cookie($name, $data) { + return setcookie($name, $data, time() + 60 * 60 * 24 * 30, '/'); + } + + function cookieGet($name, $default = null) { + if (isset($_COOKIE[$name])) + return $_COOKIE[$name]; + else + return $default; + } + + function cookieClear($name) { + setcookie ($name, false, time() - 42); + } + + function getVar($name) { + if (isset($_POST[$name])) return $_POST[$name]; + if (isset($_GET[$name])) return $_GET[$name]; + return null; + } + + function clean($s) { + $s = magic($s); + $s = htmlspecialchars($s); + return $s; + } + + function magic($s) { + if (get_magic_quotes_gpc()) $s = stripslashes($s); + return $s; + } + + function ip() { + if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) + return $_SERVER['HTTP_X_FORWARDED_FOR']; + else + return $_SERVER['REMOTE_ADDR']; + } + + function ipValid($ip) { + if ($ip == long2ip(ip2long($ip))) + return true; + return false; + } + + function jsonEncode(&$array) { + if ($array) { + $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); + return $json->encode($array); + } else + return 'ar'; + } + + function jsonDecode($encoded) { + $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); + return $json->decode($encoded); + } + + function validIP($ip) { + if ($ip == long2ip(ip2long($ip))) + return true; + return false; + } + + function ts() { + // return microtime(true); + list($usec, $sec) = explode(" ", microtime()); + return ((float)$usec + (float)$sec); + + } + + function len($string) { + $i = 0; $count = 0; + $len = strlen($string); + + while ($i < $len) { + $chr = ord($string[$i]); + $count++; + $i++; + + if ($i >= $len) break; + if ($chr & 0x80) { + $chr <<= 1; + while ($chr & 0x80) { + $i++; + $chr <<= 1; + } + } + } + + return $count; + } + + function error($err) { + echo 'Error: ' . $err; + exit; + } + + function ys($log = 1) { + global $yShout, $prefs; + if ($yShout) return $yShout; + + if ($log > $prefs['logs'] || $log < 0 || !is_numeric($log)) $log = 1; + + $log = 'log.' . $log; + return new YShout($log, loggedIn()); + } + + function dstart() { + global $ts; + + $ts = ts(); + } + + function dstop() { + global $ts; + echo 'Time elapsed: ' . ((ts() - $ts) * 100000); + exit; + } + + function login($hash) { + // echo 'login: ' . $hash . "\n"; + + $_SESSION['yLoginHash'] = $hash; + cookie('yLoginHash', $hash); + // return loggedIn(); + } + + function logout() { + $_SESSION['yLoginHash'] = ''; + cookie('yLoginHash', ''); +// cookieClear('yLoginHash'); + } + + function loggedIn() { + global $prefs; + + $loginHash = cookieGet('yLoginHash', false); +// echo 'loggedin: ' . $loginHash . "\n"; +// echo 'pw: ' . $prefs['password'] . "\n"; + + if (isset($loginHash)) return $loginHash == md5($prefs['password']); + + if (isset($_SESSION['yLoginHash'])) + return $_SESSION['yLoginHash'] == md5($prefs['password']); + + return false; + + } +?> \ No newline at end of file diff --git a/ext/chatbox/php/json.class.php b/ext/chatbox/php/json.class.php new file mode 100644 index 00000000..21deb10c --- /dev/null +++ b/ext/chatbox/php/json.class.php @@ -0,0 +1,805 @@ + +* @author Matt Knapp
+* @author Brett Stimmerman +* @copyright 2005 Michal Migurski +* @version CVS: $Id: JSON.php,v 1.30 2006/03/08 16:10:20 migurski Exp $ +* @license http://www.opensource.org/licenses/bsd-license.php +* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198 +*/ + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_SLICE', 1); + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_IN_STR', 2); + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_IN_ARR', 3); + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_IN_OBJ', 4); + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_IN_CMT', 5); + +/** +* Behavior switch for Services_JSON::decode() +*/ +define('SERVICES_JSON_LOOSE_TYPE', 16); + +/** +* Behavior switch for Services_JSON::decode() +*/ +define('SERVICES_JSON_SUPPRESS_ERRORS', 32); + +/** +* Converts to and from JSON format. +* +* Brief example of use: +* +* +* // create a new instance of Services_JSON +* $json = new Services_JSON(); +* +* // convert a complexe value to JSON notation, and send it to the browser +* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4))); +* $output = $json->encode($value); +* +* print($output); +* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]] +* +* // accept incoming POST data, assumed to be in JSON notation +* $input = file_get_contents('php://input', 1000000); +* $value = $json->decode($input); +*
+*/ +class Services_JSON +{ + /** + * constructs a new JSON instance + * + * @param int $use object behavior flags; combine with boolean-OR + * + * possible values: + * - SERVICES_JSON_LOOSE_TYPE: loose typing. + * "{...}" syntax creates associative arrays + * instead of objects in decode(). + * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. + * Values which can't be encoded (e.g. resources) + * appear as NULL instead of throwing errors. + * By default, a deeply-nested resource will + * bubble up with an error, so all return values + * from encode() should be checked with isError() + */ + function Services_JSON($use = 0) + { + $this->use = $use; + } + + /** + * convert a string from one UTF-16 char to one UTF-8 char + * + * Normally should be handled by mb_convert_encoding, but + * provides a slower PHP-only method for installations + * that lack the multibye string extension. + * + * @param string $utf16 UTF-16 character + * @return string UTF-8 character + * @access private + */ + function utf162utf8($utf16) + { + // oh please oh please oh please oh please oh please + if(function_exists('mb_convert_encoding')) { + return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); + } + + $bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); + + switch(true) { + case ((0x7F & $bytes) == $bytes): + // this case should never be reached, because we are in ASCII range + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr(0x7F & $bytes); + + case (0x07FF & $bytes) == $bytes: + // return a 2-byte UTF-8 character + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr(0xC0 | (($bytes >> 6) & 0x1F)) + . chr(0x80 | ($bytes & 0x3F)); + + case (0xFFFF & $bytes) == $bytes: + // return a 3-byte UTF-8 character + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr(0xE0 | (($bytes >> 12) & 0x0F)) + . chr(0x80 | (($bytes >> 6) & 0x3F)) + . chr(0x80 | ($bytes & 0x3F)); + } + + // ignoring UTF-32 for now, sorry + return ''; + } + + /** + * convert a string from one UTF-8 char to one UTF-16 char + * + * Normally should be handled by mb_convert_encoding, but + * provides a slower PHP-only method for installations + * that lack the multibye string extension. + * + * @param string $utf8 UTF-8 character + * @return string UTF-16 character + * @access private + */ + function utf82utf16($utf8) + { + // oh please oh please oh please oh please oh please + if(function_exists('mb_convert_encoding')) { + return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); + } + + switch(strlen($utf8)) { + case 1: + // this case should never be reached, because we are in ASCII range + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return $utf8; + + case 2: + // return a UTF-16 character from a 2-byte UTF-8 char + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr(0x07 & (ord($utf8{0}) >> 2)) + . chr((0xC0 & (ord($utf8{0}) << 6)) + | (0x3F & ord($utf8{1}))); + + case 3: + // return a UTF-16 character from a 3-byte UTF-8 char + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr((0xF0 & (ord($utf8{0}) << 4)) + | (0x0F & (ord($utf8{1}) >> 2))) + . chr((0xC0 & (ord($utf8{1}) << 6)) + | (0x7F & ord($utf8{2}))); + } + + // ignoring UTF-32 for now, sorry + return ''; + } + + /** + * encodes an arbitrary variable into JSON format + * + * @param mixed $var any number, boolean, string, array, or object to be encoded. + * see argument 1 to Services_JSON() above for array-parsing behavior. + * if var is a strng, note that encode() always expects it + * to be in ASCII or UTF-8 format! + * + * @return mixed JSON string representation of input var or an error if a problem occurs + * @access public + */ + function encode($var) + { + switch (gettype($var)) { + case 'boolean': + return $var ? 'true' : 'false'; + + case 'NULL': + return 'null'; + + case 'integer': + return (int) $var; + + case 'double': + case 'float': + return (float) $var; + + case 'string': + // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT + $ascii = ''; + $strlen_var = strlen($var); + + /* + * Iterate over every character in the string, + * escaping with a slash or encoding to UTF-8 where necessary + */ + for ($c = 0; $c < $strlen_var; ++$c) { + + $ord_var_c = ord($var{$c}); + + switch (true) { + case $ord_var_c == 0x08: + $ascii .= '\b'; + break; + case $ord_var_c == 0x09: + $ascii .= '\t'; + break; + case $ord_var_c == 0x0A: + $ascii .= '\n'; + break; + case $ord_var_c == 0x0C: + $ascii .= '\f'; + break; + case $ord_var_c == 0x0D: + $ascii .= '\r'; + break; + + case $ord_var_c == 0x22: + case $ord_var_c == 0x2F: + case $ord_var_c == 0x5C: + // double quote, slash, slosh + $ascii .= '\\'.$var{$c}; + break; + + case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): + // characters U-00000000 - U-0000007F (same as ASCII) + $ascii .= $var{$c}; + break; + + case (($ord_var_c & 0xE0) == 0xC0): + // characters U-00000080 - U-000007FF, mask 110XXXXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, ord($var{$c + 1})); + $c += 1; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xF0) == 0xE0): + // characters U-00000800 - U-0000FFFF, mask 1110XXXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2})); + $c += 2; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xF8) == 0xF0): + // characters U-00010000 - U-001FFFFF, mask 11110XXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2}), + ord($var{$c + 3})); + $c += 3; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xFC) == 0xF8): + // characters U-00200000 - U-03FFFFFF, mask 111110XX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2}), + ord($var{$c + 3}), + ord($var{$c + 4})); + $c += 4; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xFE) == 0xFC): + // characters U-04000000 - U-7FFFFFFF, mask 1111110X + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2}), + ord($var{$c + 3}), + ord($var{$c + 4}), + ord($var{$c + 5})); + $c += 5; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + } + } + + return '"'.$ascii.'"'; + + case 'array': + /* + * As per JSON spec if any array key is not an integer + * we must treat the the whole array as an object. We + * also try to catch a sparsely populated associative + * array with numeric keys here because some JS engines + * will create an array with empty indexes up to + * max_index which can cause memory issues and because + * the keys, which may be relevant, will be remapped + * otherwise. + * + * As per the ECMA and JSON specification an object may + * have any string as a property. Unfortunately due to + * a hole in the ECMA specification if the key is a + * ECMA reserved word or starts with a digit the + * parameter is only accessible using ECMAScript's + * bracket notation. + */ + + // treat as a JSON object + if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { + $properties = array_map(array($this, 'name_value'), + array_keys($var), + array_values($var)); + + foreach($properties as $property) { + if(Services_JSON::isError($property)) { + return $property; + } + } + + return '{' . join(',', $properties) . '}'; + } + + // treat it like a regular array + $elements = array_map(array($this, 'encode'), $var); + + foreach($elements as $element) { + if(Services_JSON::isError($element)) { + return $element; + } + } + + return '[' . join(',', $elements) . ']'; + + case 'object': + $vars = get_object_vars($var); + + $properties = array_map(array($this, 'name_value'), + array_keys($vars), + array_values($vars)); + + foreach($properties as $property) { + if(Services_JSON::isError($property)) { + return $property; + } + } + + return '{' . join(',', $properties) . '}'; + + default: + return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) + ? 'null' + : new Services_JSON_Error(gettype($var)." can not be encoded as JSON string"); + } + } + + /** + * array-walking function for use in generating JSON-formatted name-value pairs + * + * @param string $name name of key to use + * @param mixed $value reference to an array element to be encoded + * + * @return string JSON-formatted name-value pair, like '"name":value' + * @access private + */ + function name_value($name, $value) + { + $encoded_value = $this->encode($value); + + if(Services_JSON::isError($encoded_value)) { + return $encoded_value; + } + + return $this->encode(strval($name)) . ':' . $encoded_value; + } + + /** + * reduce a string by removing leading and trailing comments and whitespace + * + * @param $str string string value to strip of comments and whitespace + * + * @return string string value stripped of comments and whitespace + * @access private + */ + function reduce_string($str) + { + $str = preg_replace(array( + + // eliminate single line comments in '// ...' form + '#^\s*//(.+)$#m', + + // eliminate multi-line comments in '/* ... */' form, at start of string + '#^\s*/\*(.+)\*/#Us', + + // eliminate multi-line comments in '/* ... */' form, at end of string + '#/\*(.+)\*/\s*$#Us' + + ), '', $str); + + // eliminate extraneous space + return trim($str); + } + + /** + * decodes a JSON string into appropriate variable + * + * @param string $str JSON-formatted string + * + * @return mixed number, boolean, string, array, or object + * corresponding to given JSON input string. + * See argument 1 to Services_JSON() above for object-output behavior. + * Note that decode() always returns strings + * in ASCII or UTF-8 format! + * @access public + */ + function decode($str) + { + $str = $this->reduce_string($str); + + switch (strtolower($str)) { + case 'true': + return true; + + case 'false': + return false; + + case 'null': + return null; + + default: + $m = array(); + + if (is_numeric($str)) { + // Lookie-loo, it's a number + + // This would work on its own, but I'm trying to be + // good about returning integers where appropriate: + // return (float)$str; + + // Return float or int, as appropriate + return ((float)$str == (integer)$str) + ? (integer)$str + : (float)$str; + + } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { + // STRINGS RETURNED IN UTF-8 FORMAT + $delim = substr($str, 0, 1); + $chrs = substr($str, 1, -1); + $utf8 = ''; + $strlen_chrs = strlen($chrs); + + for ($c = 0; $c < $strlen_chrs; ++$c) { + + $substr_chrs_c_2 = substr($chrs, $c, 2); + $ord_chrs_c = ord($chrs{$c}); + + switch (true) { + case $substr_chrs_c_2 == '\b': + $utf8 .= chr(0x08); + ++$c; + break; + case $substr_chrs_c_2 == '\t': + $utf8 .= chr(0x09); + ++$c; + break; + case $substr_chrs_c_2 == '\n': + $utf8 .= chr(0x0A); + ++$c; + break; + case $substr_chrs_c_2 == '\f': + $utf8 .= chr(0x0C); + ++$c; + break; + case $substr_chrs_c_2 == '\r': + $utf8 .= chr(0x0D); + ++$c; + break; + + case $substr_chrs_c_2 == '\\"': + case $substr_chrs_c_2 == '\\\'': + case $substr_chrs_c_2 == '\\\\': + case $substr_chrs_c_2 == '\\/': + if (($delim == '"' && $substr_chrs_c_2 != '\\\'') || + ($delim == "'" && $substr_chrs_c_2 != '\\"')) { + $utf8 .= $chrs{++$c}; + } + break; + + case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)): + // single, escaped unicode character + $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2))) + . chr(hexdec(substr($chrs, ($c + 4), 2))); + $utf8 .= $this->utf162utf8($utf16); + $c += 5; + break; + + case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): + $utf8 .= $chrs{$c}; + break; + + case ($ord_chrs_c & 0xE0) == 0xC0: + // characters U-00000080 - U-000007FF, mask 110XXXXX + //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 2); + ++$c; + break; + + case ($ord_chrs_c & 0xF0) == 0xE0: + // characters U-00000800 - U-0000FFFF, mask 1110XXXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 3); + $c += 2; + break; + + case ($ord_chrs_c & 0xF8) == 0xF0: + // characters U-00010000 - U-001FFFFF, mask 11110XXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 4); + $c += 3; + break; + + case ($ord_chrs_c & 0xFC) == 0xF8: + // characters U-00200000 - U-03FFFFFF, mask 111110XX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 5); + $c += 4; + break; + + case ($ord_chrs_c & 0xFE) == 0xFC: + // characters U-04000000 - U-7FFFFFFF, mask 1111110X + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 6); + $c += 5; + break; + + } + + } + + return $utf8; + + } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { + // array, or object notation + + if ($str{0} == '[') { + $stk = array(SERVICES_JSON_IN_ARR); + $arr = array(); + } else { + if ($this->use & SERVICES_JSON_LOOSE_TYPE) { + $stk = array(SERVICES_JSON_IN_OBJ); + $obj = array(); + } else { + $stk = array(SERVICES_JSON_IN_OBJ); + $obj = new stdClass(); + } + } + + array_push($stk, array('what' => SERVICES_JSON_SLICE, + 'where' => 0, + 'delim' => false)); + + $chrs = substr($str, 1, -1); + $chrs = $this->reduce_string($chrs); + + if ($chrs == '') { + if (reset($stk) == SERVICES_JSON_IN_ARR) { + return $arr; + + } else { + return $obj; + + } + } + + //print("\nparsing {$chrs}\n"); + + $strlen_chrs = strlen($chrs); + + for ($c = 0; $c <= $strlen_chrs; ++$c) { + + $top = end($stk); + $substr_chrs_c_2 = substr($chrs, $c, 2); + + if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) { + // found a comma that is not inside a string, array, etc., + // OR we've reached the end of the character list + $slice = substr($chrs, $top['where'], ($c - $top['where'])); + array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false)); + //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); + + if (reset($stk) == SERVICES_JSON_IN_ARR) { + // we are in an array, so just push an element onto the stack + array_push($arr, $this->decode($slice)); + + } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { + // we are in an object, so figure + // out the property name and set an + // element in an associative array, + // for now + $parts = array(); + + if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { + // "name":value pair + $key = $this->decode($parts[1]); + $val = $this->decode($parts[2]); + + if ($this->use & SERVICES_JSON_LOOSE_TYPE) { + $obj[$key] = $val; + } else { + $obj->$key = $val; + } + } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { + // name:value pair, where name is unquoted + $key = $parts[1]; + $val = $this->decode($parts[2]); + + if ($this->use & SERVICES_JSON_LOOSE_TYPE) { + $obj[$key] = $val; + } else { + $obj->$key = $val; + } + } + + } + + } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) { + // found a quote, and we are not inside a string + array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c})); + //print("Found start of string at {$c}\n"); + + } elseif (($chrs{$c} == $top['delim']) && + ($top['what'] == SERVICES_JSON_IN_STR) && + (($chrs{$c - 1} != '\\') || + ($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) { + // found a quote, we're in a string, and it's not escaped + array_pop($stk); + //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); + + } elseif (($chrs{$c} == '[') && + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { + // found a left-bracket, and we are in an array, object, or slice + array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false)); + //print("Found start of array at {$c}\n"); + + } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) { + // found a right-bracket, and we're in an array + array_pop($stk); + //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); + + } elseif (($chrs{$c} == '{') && + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { + // found a left-brace, and we are in an array, object, or slice + array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false)); + //print("Found start of object at {$c}\n"); + + } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) { + // found a right-brace, and we're in an object + array_pop($stk); + //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); + + } elseif (($substr_chrs_c_2 == '/*') && + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { + // found a comment start, and we are in an array, object, or slice + array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false)); + $c++; + //print("Found start of comment at {$c}\n"); + + } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) { + // found a comment end, and we're in one now + array_pop($stk); + $c++; + + for ($i = $top['where']; $i <= $c; ++$i) + $chrs = substr_replace($chrs, ' ', $i, 1); + + //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); + + } + + } + + if (reset($stk) == SERVICES_JSON_IN_ARR) { + return $arr; + + } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { + return $obj; + + } + + } + } + } + + /** + * @todo Ultimately, this should just call PEAR::isError() + */ + function isError($data, $code = null) + { + if (class_exists('pear')) { + return PEAR::isError($data, $code); + } elseif (is_object($data) && (get_class($data) == 'services_json_error' || + is_subclass_of($data, 'services_json_error'))) { + return true; + } + + return false; + } +} + +if (class_exists('PEAR_Error')) { + + class Services_JSON_Error extends PEAR_Error + { + function Services_JSON_Error($message = 'unknown error', $code = null, + $mode = null, $options = null, $userinfo = null) + { + parent::PEAR_Error($message, $code, $mode, $options, $userinfo); + } + } + +} else { + + /** + * @todo Ultimately, this class shall be descended from PEAR_Error + */ + class Services_JSON_Error + { + function Services_JSON_Error($message = 'unknown error', $code = null, + $mode = null, $options = null, $userinfo = null) + { + + } + } + +} + +?> \ No newline at end of file diff --git a/ext/chatbox/php/yshout.class.php b/ext/chatbox/php/yshout.class.php new file mode 100644 index 00000000..b02f6689 --- /dev/null +++ b/ext/chatbox/php/yshout.class.php @@ -0,0 +1,253 @@ + + +class YShout { + + function YShout($path, $admin = false) { + global $storage; + // Redo to check for folders or just not break, because nonexistent files should be allowed. + // if (!file_exists($path)) error('That file does not exist.'); + + $this->storage = new $storage($path, true); + $this->admin = $admin; + } + + function posts() { + global $null; + $this->storage->open(); + $s = $this->storage->load(); + $this->storage->close($null); + + if ($s) + return $s['posts']; + } + + function info() { + global $null; + $s = $this->storage->open(true); + + $this->storage->close($null); + + if ($s) + return $s['info']; + } + + function postsAfter($ts) { + $allPosts = $this->posts(); + + $posts = array(); + + /* for ($i = sizeof($allPosts) - 1; $i > -1; $i--) { + $post = $allPosts[$i]; + + if ($post['timestamp'] > $ts) + $posts[] = $post; + } */ + + foreach($allPosts as $post) { + if ($post['timestamp'] > $ts) + $posts[] = $post; + } + + $this->postProcess($posts); + return $posts; + } + + function latestPosts($num) { + $allPosts = $this->posts(); + $posts = array_slice($allPosts, -$num, $num); + + $this->postProcess($posts); + return array_values($posts); + } + + function hasPostsAfter($ts) { + $info = $this->info(); + $timestamp = $info['latestTimestamp']; + return $timestamp > $ts; + } + + function post($nickname, $message) { + global $prefs; + + if ($this->banned(ip()) /* && !$this->admin*/) return false; + + if (!$this->validate($message, $prefs['messageLength'])) return false; + if (!$this->validate($nickname, $prefs['nicknameLength'])) return false; + + $message = trim(clean($message)); + $nickname = trim(clean($nickname)); + + if ($message == '') return false; + if ($nickname == '') return false; + + $timestamp = ts(); + + $message = $this->censor($message); + $nickname = $this->censor($nickname); + + $post = array( + 'nickname' => $nickname, + 'message' => $message, + 'timestamp' => $timestamp, + 'admin' => $this->admin, + 'uid' => md5($timestamp . ' ' . $nickname), + 'adminInfo' => array( + 'ip' => ip() + ) + ); + + $s = $this->storage->open(true); + + $s['posts'][] = $post; + + if (sizeof($s['posts']) > $prefs['history']) + $this->truncate($s['posts']); + + $s['info']['latestTimestamp'] = $post['timestamp']; + + $this->storage->close($s); + $this->postProcess($post); + return $post; + } + + function truncate(&$array) { + global $prefs; + + $array = array_slice($array, -$prefs['history']); + $array = array_values($array); + } + + function clear() { + global $null; + + $this->storage->open(true); + $this->storage->resetArray(); + // ? Scared to touch it... Misspelled though. Update: Touched! Used to be $nulls... + $this->storage->close($null); + } + + function bans() { + global $storage, $null; + + $s = new $storage('yshout.bans'); + $s->open(); + $bans = $s->load(); + $s->close($null); + + return $bans; + } + + function ban($ip, $nickname = '', $info = '') { + global $storage; + + $s = new $storage('yshout.bans'); + $bans = $s->open(true); + + $bans[] = array( + 'ip' => $ip, + 'nickname' => $nickname, + 'info' => $info, + 'timestamp' => ts() + ); + + $s->close($bans); + } + + function banned($ip) { + global $storage, $null; + + $s = new $storage('yshout.bans'); + $bans = $s->open(true); + $s->close($null); + + foreach($bans as $ban) { + if ($ban['ip'] == $ip) + return true; + } + + return false; + } + + function unban($ip) { + global $storage; + + $s = new $storage('yshout.bans'); + $bans = $s->open(true); + + foreach($bans as $key=>$value) + if ($value['ip'] == $ip) { + unset($bans[$key]); + } + + $bans = array_values($bans); + $s->close($bans); + + } + + function unbanAll() { + global $storage, $null; + + $s = new $storage('yshout.bans'); + $s->open(true); + $s->resetArray(); + $s->close($null); + } + + function delete($uid) { + global $prefs, $storage; + + + $s = $this->storage->open(true); + + $posts = $s['posts']; + + foreach($posts as $key=>$value) { + if (!isset($value['uid'])) + unset($posts['key']); + else + if($value['uid'] == $uid) + unset($posts[$key]); + } + + $s['posts'] = array_values($posts); + $this->storage->close($s); + + return true; + } + + function validate($str, $maxLen) { + return len($str) <= $maxLen; + } + + function censor($str) { + global $prefs; + + $cWords = explode(' ', $prefs['censorWords']); + $words = explode(' ', $str); + $endings = '|ed|es|ing|s|er|ers'; + $arrEndings = explode('|', $endings); + + foreach ($cWords as $cWord) foreach ($words as $i=>$word) { + $pattern = '/^(' . $cWord . ')+(' . $endings . ')\W*$/i'; + $words[$i] = preg_replace($pattern, str_repeat('*', strlen($word)), $word); + } + + return implode(' ', $words); + } + + function postProcess(&$post) { + if (isset($post['message'])) { + if ($this->banned($post['adminInfo']['ip'])) $post['banned'] = true; + if (!$this->admin) unset($post['adminInfo']); + } else { + foreach($post as $key=>$value) { + if ($this->banned($value['adminInfo']['ip'])) $post[$key]['banned'] = true; + if (!$this->admin) unset($post[$key]['adminInfo']); + } + } + } + +} + + +?> \ No newline at end of file diff --git a/ext/chatbox/preferences.php b/ext/chatbox/preferences.php new file mode 100644 index 00000000..7d394c85 --- /dev/null +++ b/ext/chatbox/preferences.php @@ -0,0 +1,74 @@ + + // If you want to change the nickname, the line below is the one to modify. + // Simply set $overrideNickname to whatever variable you want to appear as the nickname, + // or leave it null to use the set nicknames. + + $overrideNickname = null; + + $storage = 'FileStorage'; + + function loadPrefs() { + global $prefs, $storage, $null; + $s = new $storage('yshout.prefs'); + $s->open(); + $prefs = $s->load(); + $s->close($null); + } + + function savePrefs($newPrefs) { + global $prefs, $storage; + + $s = new $storage('yshout.prefs'); + $s->open(true); + $s->close($newPrefs); + $prefs = $newPrefs; + } + + function resetPrefs() { + $defaultPrefs = array( + 'password' => 'fortytwo', // The password for the CP + + 'refresh' => 6000, // Refresh rate + + 'logs' => 5, // Amount of different log files to allow + 'history' => 200, // Shouts to keep in history + + 'inverse' => false, // Inverse shoutbox / form on top + + 'truncate' => 15, // Truncate messages client-side + 'doTruncate' => true, // Truncate messages? + + 'timestamp' => 12, // Timestamp format 12- or 24-hour + + 'defaultNickname' => 'Nickname', + 'defaultMessage' => 'Message Text', + 'defaultSubmit' => 'Shout!', + 'showSubmit' => true, + + 'nicknameLength' => 25, + 'messageLength' => 175, + + 'nicknameSeparator' => ':', + + 'flood' => true, + 'floodTimeout' => 5000, + 'floodMessages' => 4, + 'floodDisable' => 8000, + 'floodDelete' => false, + + 'autobanFlood' => 0, // Autoban people for flooding after X messages + + 'censorWords' => 'fuck shit bitch ass', + + 'postFormLink' => 'history', + + 'info' => 'inline' + ); + + savePrefs($defaultPrefs); + } + + resetPrefs(); + //loadPrefs(); + +?> diff --git a/ext/chatbox/smileys/biggrin.gif b/ext/chatbox/smileys/biggrin.gif new file mode 100644 index 00000000..d3527723 Binary files /dev/null and b/ext/chatbox/smileys/biggrin.gif differ diff --git a/ext/chatbox/smileys/confused.gif b/ext/chatbox/smileys/confused.gif new file mode 100644 index 00000000..0c49e069 Binary files /dev/null and b/ext/chatbox/smileys/confused.gif differ diff --git a/ext/chatbox/smileys/cool.gif b/ext/chatbox/smileys/cool.gif new file mode 100644 index 00000000..cead0306 Binary files /dev/null and b/ext/chatbox/smileys/cool.gif differ diff --git a/ext/chatbox/smileys/cry.gif b/ext/chatbox/smileys/cry.gif new file mode 100644 index 00000000..7d54b1f9 Binary files /dev/null and b/ext/chatbox/smileys/cry.gif differ diff --git a/ext/chatbox/smileys/eek.gif b/ext/chatbox/smileys/eek.gif new file mode 100644 index 00000000..5d397810 Binary files /dev/null and b/ext/chatbox/smileys/eek.gif differ diff --git a/ext/chatbox/smileys/evil.gif b/ext/chatbox/smileys/evil.gif new file mode 100644 index 00000000..ab1aa8e1 Binary files /dev/null and b/ext/chatbox/smileys/evil.gif differ diff --git a/ext/chatbox/smileys/lol.gif b/ext/chatbox/smileys/lol.gif new file mode 100644 index 00000000..374ba150 Binary files /dev/null and b/ext/chatbox/smileys/lol.gif differ diff --git a/ext/chatbox/smileys/mad.gif b/ext/chatbox/smileys/mad.gif new file mode 100644 index 00000000..1f6c3c2f Binary files /dev/null and b/ext/chatbox/smileys/mad.gif differ diff --git a/ext/chatbox/smileys/mrgreen.gif b/ext/chatbox/smileys/mrgreen.gif new file mode 100644 index 00000000..b54cd0f9 Binary files /dev/null and b/ext/chatbox/smileys/mrgreen.gif differ diff --git a/ext/chatbox/smileys/neutral.gif b/ext/chatbox/smileys/neutral.gif new file mode 100644 index 00000000..4f311567 Binary files /dev/null and b/ext/chatbox/smileys/neutral.gif differ diff --git a/ext/chatbox/smileys/razz.gif b/ext/chatbox/smileys/razz.gif new file mode 100644 index 00000000..29da2a2f Binary files /dev/null and b/ext/chatbox/smileys/razz.gif differ diff --git a/ext/chatbox/smileys/redface.gif b/ext/chatbox/smileys/redface.gif new file mode 100644 index 00000000..ad762832 Binary files /dev/null and b/ext/chatbox/smileys/redface.gif differ diff --git a/ext/chatbox/smileys/rolleyes.gif b/ext/chatbox/smileys/rolleyes.gif new file mode 100644 index 00000000..d7f5f2f4 Binary files /dev/null and b/ext/chatbox/smileys/rolleyes.gif differ diff --git a/ext/chatbox/smileys/sad.gif b/ext/chatbox/smileys/sad.gif new file mode 100644 index 00000000..d2ac78c0 Binary files /dev/null and b/ext/chatbox/smileys/sad.gif differ diff --git a/ext/chatbox/smileys/smile.gif b/ext/chatbox/smileys/smile.gif new file mode 100644 index 00000000..7b1f6d30 Binary files /dev/null and b/ext/chatbox/smileys/smile.gif differ diff --git a/ext/chatbox/smileys/surprised.gif b/ext/chatbox/smileys/surprised.gif new file mode 100644 index 00000000..cb214243 Binary files /dev/null and b/ext/chatbox/smileys/surprised.gif differ diff --git a/ext/chatbox/smileys/twisted.gif b/ext/chatbox/smileys/twisted.gif new file mode 100644 index 00000000..502fe247 Binary files /dev/null and b/ext/chatbox/smileys/twisted.gif differ diff --git a/ext/chatbox/smileys/wink.gif b/ext/chatbox/smileys/wink.gif new file mode 100644 index 00000000..d1482880 Binary files /dev/null and b/ext/chatbox/smileys/wink.gif differ diff --git a/ext/chatbox/yshout.php b/ext/chatbox/yshout.php new file mode 100644 index 00000000..8b35afd5 --- /dev/null +++ b/ext/chatbox/yshout.php @@ -0,0 +1,39 @@ + +error_reporting(E_ALL); +ob_start(); +set_error_handler('errorOccurred'); +include 'include.php'; +if (isset($_POST['reqFor'])) + switch($_POST['reqFor']) { + case 'shout': + + $ajax = new AjaxCall(); + $ajax->process(); + break; + + case 'history': + + // echo $_POST['log']; + $ajax = new AjaxCall($_POST['log']); + $ajax->process(); + break; + + default: + exit; + } +else + include 'example.html'; + +function errorOccurred($num, $str, $file, $line) { + $err = array ( + 'yError' => "$str. \n File: $file \n Line: $line" + ); + + if (function_exists('jsonEncode')) + echo jsonEncode($err); + else + echo $err['yError']; + exit; +} + +?> \ No newline at end of file