# HG changeset patch # User Dan # Date 1232507297 18000 # Node ID a8f0e99883d14c09fde2f24dced216edb2aabba2 # Parent 508400fc5282df03647196d93879e4da849557cf Web interface can now update with AJAX diff -r 508400fc5282 -r a8f0e99883d1 htdocs/ajax-active.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/htdocs/ajax-active.php Tue Jan 20 22:08:17 2009 -0500 @@ -0,0 +1,52 @@ + +

Active members

+

For the last 1, 5, and 15 minutes: + +

+

Currently active members:

+

These people have posted in the last 3 minutes:

+ +

Last 20 minutes:

+ + diff -r 508400fc5282 -r a8f0e99883d1 htdocs/ajax-update.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/htdocs/ajax-update.js Tue Jan 20 22:08:17 2009 -0500 @@ -0,0 +1,121 @@ +function update_stats() +{ + var body = document.getElementsByTagName('body')[0]; + body.style.cursor = 'wait'; + ajaxGet('ajax-active.php', function() + { + if ( window.ajax.readyState == 4 && window.ajax.status == 200 ) + { + document.getElementById('active-members').innerHTML = ajax.responseText; + } + }); + var images = document.getElementsByTagName('img'); + for ( var i = 0; i < images.length; i++ ) + { + var image = images[i]; + if ( image.className.indexOf('graph') != -1 ) + { + image.src = (String(image.src)).replace(/&seed=[0-9]+$/, '') + '&seed=' + Math.floor(Math.random() * 100000); + } + } + window.setTimeout(function() + { + body.style.cursor = null; + }, 250); +} + +window.onload = function() +{ + var ivl = parseFloat(readCookie('interval')); + if ( ivl == 0 || isNaN(ivl) ) + ivl = 30.0; + + var textbox = document.getElementById('update_ivl'); + textbox.value = String(ivl); + textbox.onkeyup = process_update_ivl; + + ivl = parseInt(ivl * 1000); + + window.ajax_update_ivl = window.setInterval('update_stats();', ivl); +} + +function set_update_ivl(ivl) +{ + window.clearInterval(ajax_update_ivl); + createCookie('interval', ivl, 3650); + ivl = parseInt(ivl * 1000); + + window.ajax_update_ivl = window.setInterval('update_stats();', ivl); +} + +function process_update_ivl() +{ + var val = parseFloat(this.value); + + if ( isNaN(val) || val < 5 ) + val = 10; + + set_update_ivl(val); +} + +/** + * Core AJAX library + */ + +function ajaxMakeXHR() +{ + var ajax; + if (window.XMLHttpRequest) + { + ajax = new XMLHttpRequest(); + } + else + { + if (window.ActiveXObject) + { + ajax = new ActiveXObject("Microsoft.XMLHTTP"); + } + else + { + return false; + } + } + return ajax; +} + +function ajaxGet(uri, f, call_editor_safe) { + window.ajax = ajaxMakeXHR(); + if ( !ajax ) + { + return false; + } + ajax.onreadystatechange = f; + ajax.open('GET', uri, true); + ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" ); + ajax.send(null); +} + +function ajaxPost(uri, parms, f, call_editor_safe) { + // Is the editor open? + window.ajax = ajaxMakeXHR(); + if ( !ajax ) + { + return false; + } + ajax.onreadystatechange = f; + ajax.open('POST', uri, true); + ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + // Setting Content-length in Safari triggers a warning + if ( !is_Safari ) + { + ajax.setRequestHeader("Content-length", parms.length); + } + ajax.setRequestHeader("Connection", "close"); + ajax.send(parms); +} + +// Cookie manipulation +function readCookie(name) {var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;} +function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";} +function eraseCookie(name) {createCookie(name,"",-1);} + diff -r 508400fc5282 -r a8f0e99883d1 htdocs/index.php --- a/htdocs/index.php Tue Jan 20 22:08:07 2009 -0500 +++ b/htdocs/index.php Tue Jan 20 22:08:17 2009 -0500 @@ -1,6 +1,6 @@ +

+

Update every seconds
+ (Javascript required, min. 5 secs, default 30)
+

-

Active members

-

For the last 1, 5, and 15 minutes: - -

-

Currently active members:

-

These people have posted in the last 3 minutes:

- -

Last 20 minutes:

- +

Last 60 minutes

- Graph image + Graph image

Last 24 hours

- Graph image + Graph image

Last 2 weeks

- Graph image + Graph image msg(eb_censor_words($doctor[$message['nick']]->listen($message['message']))); + $chan->msg(eb_censor_words("{$message['nick']}: " . $doctor[$message['nick']]->listen($message['message']))); } }