Permalink
Browse files

moved ajaxISB to a branch

  • Loading branch information...
1 parent 0b640a8 commit 78e21c96e94bf37b9556aab91fcbd50e4e2330f2 @mpapis committed Jan 4, 2012
Showing with 0 additions and 390 deletions.
  1. +0 −123 ajaxISB/ajax.js
  2. +0 −63 ajaxISB/common.php
  3. 0 ajaxISB/history.htm
  4. +0 −33 ajaxISB/index.html
  5. +0 −15 ajaxISB/messages.php
  6. +0 −38 ajaxISB/mycached.php
  7. +0 −66 ajaxISB/status.php
  8. +0 −52 ajaxISB/write.php
View
123 ajaxISB/ajax.js
@@ -1,123 +0,0 @@
-<!--
-function getHttpRequest()
-{
- var req;
- if (window.XMLHttpRequest) {
- req = new XMLHttpRequest();
- } else if (window.ActiveXObject) {
- req = new ActiveXObject("Microsoft.XMLHTTP");
- } else {
- req = null;
- }
- return req;
-}
-
-var disp_req = getHttpRequest();
-var stat_req = getHttpRequest();
-var mesg_req = getHttpRequest();
-
-var user_pos = -1;
-var user = "";
-var ka1 = setInterval("refreshStatus()", 5000);
-var ka2 = setInterval("refreshMessages()",3333);
-
-function initISB()
-{
- document.all.msg_text.focus();
- var loc = new String(window.location);
- user_pos = loc.indexOf("?name="); //if -1 no user name specified
- if (user_pos>-1)
- {
- user = loc.substring(user_pos+6,9999);
- refreshStatus();
- refreshMessages();
- }
- else
- {
- clearInterval(ka1);
- clearInterval(ka2);
- user_pos=0;
- user=prompt("Podaj nazwe uytkownika","");
- if (user!=null)
- {
- window.location += "?name="+user;
- window.reload();
- return;
- }
- }
-}
-
-function sendMessageResponse()
-{
- // only if req shows "complete"
- if (mesg_req.readyState == 4) {
- // only if not "OK"
- if (mesg_req.status == 200) {
- refreshMessages();
- }
- else
- {
- alert("Niepowiodo si�wysyanie wiadomoci:\n" + mesg_req.statusText);
- }
- }
-}
-
-function sendMessage()
-{
- if (user_pos>-1)
- {
- mesg_req.open("GET","write.php?name="+user+"&body="+document.getElementById("msg_text").value);
- mesg_req.onreadystatechange = sendMessageResponse;
- mesg_req.send("name="+user+"&body="+document.getElementById("msg_text").value);
- document.getElementById("msg_text").value = "";
- }
- return false;
-}
-
-function refreshStatusResponse()
-{
- // only if req shows "complete"
- if (stat_req.readyState == 4) {
- // only if not "OK"
- if (stat_req.status == 200) {
- document.getElementById("status").innerHTML=stat_req.responseText;
- } else {
- document.getElementById("status").innerHTML=user+"<br />Niemona pobra�listy uytkownik�<br />"+stat_req.statusText;
- }
- }
-}
-
-function refreshStatus()
-{
- if (user_pos>-1)
- {
- stat_req.open("GET","status.php?name="+user);
- stat_req.onreadystatechange = refreshStatusResponse;
- stat_req.send("name="+user);
- }
-}
-
-function refreshMessagesResponse()
-{
- // only if req shows "complete"
- if (disp_req.readyState == 4) {
- // only if not "OK"
- if (disp_req.status == 200) {
- document.getElementById("display").innerHTML=disp_req.responseText;
- } else {
- document.getElementById("display").innerHTML="Interaktywny ShoutBox, Niemona pobra�wiadomoci<br />"+disp_req.statusText;
- }
- }
-}
-
-function refreshMessages()
-{
- if (user_pos>-1)
- {
- disp_req.open("GET","messages.php");
- disp_req.onreadystatechange = refreshMessagesResponse;
- disp_req.send("");
- }
-}
-
-//-->
View
63 ajaxISB/common.php
@@ -1,63 +0,0 @@
-<?PHP
-
-error_reporting(E_ALL);
-
-require 'mycached.php';
-
-define('TAB', "\t");
-define('CR', "\n");
-define('def_messages',3);
-define('def_status',2);
-
-$show_shouts = 14;
-
-if(!function_exists('file_put_contents'))
-{
- function file_put_contents($filename, $data)
- {
- if(($h = @fopen($filename, 'w')) === false)
- {
- return false;
- }
- if(($bytes = @fwrite($h, $data)) === false)
- {
- return false;
- }
- fclose($h);
- return $bytes;
- }
-}
-
-if(!function_exists('file_get_contents'))
-{
- function file_get_contents($filename)
- {
- return implode('', file($filename));
- }
-}
-
-function datef($timestamp, $fmt = 'G:i:s') //Y.n.j G:i:s
-{
- if($timestamp < 1)
- {
- return 'no date';
- }
- return date($fmt, $timestamp);
-}
-
-function formatf($text)
-{
- $text = str_replace("\r\n", "\n", $text);
- $text = nl2br($text);
- $text = str_replace('\\\'', '\'', $text); //Without this, servers with magic quotes on would literally display \' instead of '
- $text = str_replace('\\\\', '\\', $text); //So people can post backslashes...for whatever reason
- $text = str_replace("\n", '', $text); //Temporary;
- return trim($text);
-}
-
-function formatfall($time_to_add,$name_to_add,$body_to_add)
-{
- return "<b>".$time_to_add." ".$name_to_add.":</b> ".$body_to_add."<br />";
-}
-
-?>
View
0 ajaxISB/history.htm
No changes.
View
33 ajaxISB/index.html
@@ -1,33 +0,0 @@
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
- <title>Interactive ShoutBox</title>
- <script src="./ajax.js"></script>
- </head>
- <body><!-- onLoad="initISB();" -->
- <table width="100%" height="500" border=1 >
- <tr valign=top>
- <td width="*">
- <div id=write name=write>
- <form id=write_form name=write_form action="" onSubmit="return sendMessage()">
- <input type="text" id="msg_text" name="msg_text" value="" size="50" maxsize="200" style="width:100%" />
- </form>
- </div>
- <hr style="height=2px" />
- <div id="display" name="display">
- Interaktywny ShoutBox, Prosze czeka�trwa adowanie wiadomoci.
- </div>
- </td>
- <td width="120">
- <b>Uytkownicy:</b>
- <div id="status" name="status">
- adowanie
- </div>
- </td>
- </tr>
- </table>
- <script language=JavaScript>
- initISB();
- </script>
- </body>
-</html>
View
15 ajaxISB/messages.php
@@ -1,15 +0,0 @@
-<?php
-
-require 'common.php';
-
-//Error Reporting. ~_^
-//error_reporting(E_ALL);
-
-$content = get_value(def_messages);
-if (!is_array($content)) $content = array();
-foreach($content as $nr => $line)
-{
- $line1 = explode(TAB,$line);
- echo(formatfall($line1[0],$line1[1],$line1[2]));
-}
-?>
View
38 ajaxISB/mycached.php
@@ -1,38 +0,0 @@
-<?php
-define('__key',1647675);
-
-function store_value($key,$var)
-{
- $semid = sem_get(__key+1, 1, 0644 );
- if ($sem = sem_acquire($semid))
- {
- $shmid = shm_attach(__key);
- if ($shmid>0)
- {
- shm_put_var($shmid,$key,$var);
- @shm_detach($shmid);
- }
- }
- @sem_release($sem);
- @sem_remove($semid);
- return true;
-}
-
-function get_value($key)
-{
- $semid = sem_get(__key+1, 1, 0644 );
- if ($sem = sem_acquire($semid))
- {
- $shmid = shm_attach(__key);
- if ($shmid>0)
- {
- $ret = shm_get_var($shmid,$key);
- @shm_detach($shmid);
- }
- }
- @sem_release($sem);
- @sem_remove($semid);
- return $ret;
-}
-
-?>
View
66 ajaxISB/status.php
@@ -1,66 +0,0 @@
-<?php
-
-require 'common.php';
-
-$status=get_value(def_status);
-
-if (!is_array($status))
- $status = array();
-
-$now = time();
-if (isset($_REQUEST['name']))
-{
- $name = $_REQUEST['name'];
-}
-else
-{
- $name = 'Admin/Guest';
-}
-
-foreach($status as $nr => $stat)
-{
- if (strpos($stat,$name)!==false)
- {
- $status[$nr]=$name . TAB . $now;
- $exists=true;
- break;
- }
-}
-if ($exists!==true)
-{
- array_push($status,$name . TAB . $now);
-}
-
-$status_new = array();
-
-foreach($status as $nr => $stat)
-{
- $params = explode(TAB,$stat);
- if ($params[1]>$now-60)
- {
- array_push($status_new,$stat);
- }
-}
-
-store_value(def_status,$status_new);
-
-$users="";
-
-foreach($status_new as $nr => $stat)
-{
- $params = explode(TAB,$stat);
- if ($params[1]<$now-11)
- {
- $sec_nr = $now-$params[1];
- $sec = '(' . $sec_nr . ')';
- }
- else
- {
- $sec = '';
- }
- $users .= $params[0] . '' . $sec . ',<br>';
-}
-
-echo $users;
-
-?>
View
52 ajaxISB/write.php
@@ -1,52 +0,0 @@
-<?php
-
-session_start();
-session_register('last_data');
-session_register('last_data_nr');
-
-require 'common.php';
-
-//if(isset($_GET['shout']))
-{
- if(empty($_GET['name']) || empty($_GET['body']))
- {
- echo("Błąd");
- }
- else
- {
- $time_to_add = datef(time());
- $name_to_add = formatf($_GET['name']);
- $body_to_add = formatf($_GET['body']);
-
- $content = get_value(def_messages);
- if (!is_array($content)) $content = array();
-
- if( empty($_SESSION['last_data']) || ($_SESSION['last_data'] != $body_to_add) || ($content[0][2]!=$_SESSION['last_data']) )
- {
- array_unshift($content,$time_to_add.TAB.$name_to_add.TAB.$body_to_add);
- $_SESSION['last_data']=$body_to_add;
- $_SESSION['last_data_nr']=1;
- }
- else
- {
- $_SESSION['last_data_nr']=$_SESSION['last_data_nr']+1;
- $line1 = explode(TAB,$content[0]);
- $line1[0]=$time_to_add;
- $line1[2]=$body_to_add . ' <b>(x ' . $_SESSION['last_data_nr'] . ')</b>';
- $content[0] = $line1[0] . ":" . $line1[0] . ":" . $line1[0];
- }
-
- $count_l = count($content);
- while ( count($content) > $show_shouts )
- {
- array_pop($content);
- }
- store_value(def_messages, $content);
-
- $content = file_get_contents('history.htm');
- $content = formatfall($time_to_add,$name_to_add,$body_to_add) . CR . $content;
- file_put_contents('history.htm', trim($content));
- echo("OK");
- }
-}
-?>

0 comments on commit 78e21c9

Please sign in to comment.