芝麻web文件管理V1.00
编辑当前文件:/home/jambtst2015/public_html/giraffeng.com/chatfiles/chatfunctions.js
// PHP Script Chat - http://coursesweb.net/ var chatuserset = 0; // used to check if chat user name is set var logoutchat = 0; // if set 1, user leaves the chat, to remove it from Online list var c_subdir = document.getElementById('chatwindow').getAttribute('data-subdir'); // get the subdir with chatrooms var chatroom = document.getElementById('chatroom') ? document.getElementById('chatroom').value : document.getElementById('s_room').innerHTML; // store chat room var callphp = 0; // number of seconds till access frequently "setchat.php" var nrchatusers = 1; // store number of chat users online var setchat = 'chatfiles/setchat.php'; // file accesed when add chat, or actualise user var getchat = function() {return 'chattxt/' + c_subdir +chatroom +'.txt';}; // TXT file with chat content of current room var ajxsend = 0; // to control accessing Ajax var lastaddedc = 1; // stores Timestamp of last added chat var playbeep = 2; // if 1 not beep, if 2 beep var beepfile = 'beep1.wav'; // the name of WAV file used for beep sound var refresh_usrs = 0; // when its rest to 2 is 0, refreshes online users list (in setHtmlChat()) /** Functions for cookie **/ // Check cookie and return the value function GetCookie(name) { var result = '0'; var myCookie = " " + document.cookie + ";"; // all the strings for cookie start with space, end with ; var searchName = " " + name + "="; // search for data between 'name' and the next '=' var startOfCookie = myCookie.indexOf(searchName); if (startOfCookie != -1) { // if found data startOfCookie += searchName.length; // omitte the previous cookie name var endOfCookie = myCookie.indexOf(";", startOfCookie); result = unescape(myCookie.substring(startOfCookie, endOfCookie)); } return result; } // to deleete cookie function delCookie(name) { var aday = 3*24*60*60*1000; var expDate = new Date(); expDate.setTime (expDate.getTime() - aday); document.cookie = name + "=deletes; expires=" + expDate.toGMTString(); // hide field to add texts and shows area to add name /code, or to enter in chat if(document.getElementById('name_code')) document.getElementById('name_code').style.display = 'block'; if(document.getElementById('chatadd')) document.getElementById('chatadd').style.display = 'none'; logoutchat = 1; // set to delete the user from list refresh_usrs = 0; // sets to can refresh online users list chatuserset = 0; // set not with a name in chat } // If no user added in form, calls to get chat user name from cookie var cookie_namec = (document.getElementById('chatuser') && document.getElementById('chatuser').value.length>1) ? '0' : GetCookie('name_c'); if (cookie_namec!='0' && document.getElementById('name_code')) { callphp = 0; // set "callphp" to 0 to force next ajax access to php file // Hides name /code, show field to add text chat document.getElementById('name_code').style.display = 'none'; document.getElementById('chatadd').style.display = 'block'; // Add cookie value in form to #chatuser document.getElementById('chatuser').value = cookie_namec; logoutchat = 0; // set to not delete the user from list chatuserset = 1; } // If it is set cookie for room var cookie_roomc = GetCookie('room_c'); // get chat room name from cookie if (cookie_roomc!='0') { var chatrooms = document.getElementById('chatrooms').getElementsByTagName('span'); // Get
with chatroom // Removes "id" from
with chatroom, and set this ID to Span with room name from cookie for (var i=0; i
in #lastaddedc to play function playBeep(lastchat) { if(lastchat != lastaddedc) { lastaddedc = lastchat; document.getElementById('chatbeep').innerHTML= '
'; } } // sets sound-beep on or off (playbeep 2 or 1), change image for playBeep() function setPlayBeep(imgset) { playbeep = (playbeep == 1) ? 2 : 1; imgset.src = 'chatex/playbeep'+playbeep+'.png'; // Sets data in cookie var name_cookie = 'beep_c'; var val_cookie = playbeep; var oned = 48*60*60*1000; // Cookie expiration, two days in milliseconds var expDate = new Date(); expDate.setTime(expDate.getTime()+oned); document.cookie = name_cookie + "=" + escape(val_cookie) + "; expires=" + expDate.toGMTString(); // sets cookie } /** Functions for checkings and settings **/ // Check if the name is already used function checkNameC(name_c) { var nameused = 0; if(document.getElementById('chatusersli')) { var chatusersli = document.getElementById('chatusersli').getElementsByTagName('li'); // gets the list with chat users var nrchatusersli = chatusersli.length; // Traverse chat users list for (var i=0; i
with chatroom // Removes "id" from
with chatroom for (var i=0; i
200) { alert(texts.err_textchat); text.adchat.focus(); } else { // sends data to Ajax var send_chat = "adchat="+encodeURIComponent(text.adchat.value)+"&chatuser="+text.chatuser.value; ajxsend = 1; // Ajax busy now ajaxF(setchat, send_chat); text.adchat.value = ''; } } else setNameC(text); return false; } /** Start - functions to add URL, Format text, and Smiles in textarea **/ // check and pass the URL function setUrl(idadd) { var url = window.prompt(texts.addurl); // open Prompt to add URL // check if a correct URL (without http://), send it to addChatBIU(), else alert if (url.match(/^(www.){0,1}([a-zA-z0-9_,+ -]+[.]+)/)) addChatBIU('[url=http://'+url+']','[/url]', idadd); else alert(texts.err_addurl); } // Adaugare font B, I, U function addChatBIU(start, end, zona) { var adchat = document.getElementById(zona); var IE = /*@cc_on!@*/false; // this variable is false in all browsers, except IE if (IE) { adchat.value = adchat.value + start + end; // Add in field the initial values + received dta var pos = adchat.value.length - end.length; // Sets location for cursor position // position the cursor through a selected area range = adchat.createTextRange(); range.collapse(true); range.moveEnd('character', pos); // start position range.moveStart('character', pos); // end position range.select(); // selects the zone } else if (adchat.selectionStart || adchat.selectionStart == "0") { var startPos = adchat.selectionStart; var endPos = adchat.selectionEnd; adchat.value = adchat.value.substring(0, startPos) + start + adchat.value.substring(startPos, endPos) + end + adchat.value.substring(endPos, adchat.value.length); // Place the cursor between formats in #adchat adchat.setSelectionRange((endPos+start.length),(endPos+start.length)); adchat.focus(); } } // for clicked smile in element with ID passed in "idadd" function addSmile(smile, idadd) { var tarea_com = document.getElementById(idadd); tarea_com.value += smile; tarea_com.focus(); } // object to convert BBCODE in HTML tags var bbcodeParser={};(function(){var token_match=/{[A-Z_]+[0-9]*}|:\)|:\(|:P|:D|:S|:O|:=\)|:\|H|:X|:\-\*/ig;bbcodeParser.tokens={'URL':'((?:(?:[a-z][a-z\\d+\\-.]*:\\/{2}(?:(?:[a-z0-9\\-._~\\!$&\'*+,;=:@|]+|%[\\dA-F]{2})+|[0-9.]+|\\[[a-z0-9.]+:[a-z0-9.]+:[a-z0-9.:]+\\])(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~\\!$&\'*+,;=:@|]+|%[\\dA-F]{2})*)*(?:\\?(?:[a-z0-9\\-._~\\!$&\'*+,;=:@\\/?|]+|%[\\dA-F]{2})*)?(?:#(?:[a-z0-9\\-._~\\!$&\'*+,;=:@\\/?|]+|%[\\dA-F]{2})*)?)|(?:www\\.(?:[a-z0-9\\-._~\\!$&\'*+,;=:@|]+|%[\\dA-F]{2})+(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~\\!$&\'*+,;=:@|]+|%[\\dA-F]{2})*)*(?:\\?(?:[a-z0-9\\-._~\\!$&\'*+,;=:@\\/?|]+|%[\\dA-F]{2})*)?(?:#(?:[a-z0-9\\-._~\\!$&\'*+,;=:@\\/?|]+|%[\\dA-F]{2})*)?)))','LOCAL_URL':'((?:[a-z0-9\-._~\!$&\'()*+,;=:@|]+|%[\dA-F]{2})*(?:\/(?:[a-z0-9\-._~\!$&\'()*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~\!$&\'()*+,;=:@\/?|]+|%[\dA-F]{2})*)?(?:#(?:[a-z0-9\-._~\!$&\'()*+,;=:@\/?|]+|%[\dA-F]{2})*)?)','EMAIL':'((?:[\\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\\w\!\#$\%\'\*\+\-\/\=\?\^\`{\|\}\~]|&)+@(?:(?:(?:(?:(?:[a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(?:\\d{1,3}\.){3}\\d{1,3}(?:\:\\d{1,5})?))','TEXT':'(.*?)','SIMPLETEXT':'([a-zA-Z0-9-+.,_ ]+)','INTTEXT':'([a-zA-Z0-9-+,_. ]+)','IDENTIFIER':'([a-zA-Z0-9-_]+)','COLOR':'([a-z]+|#[0-9abcdef]+)','NUMBER':'([0-9]+)'};bbcodeParser.bbcode_matches=[];bbcodeParser.html_tpls=[];bbcodeParser._getRegEx=function(str){var matches=str.match(token_match);var i=0;var replacement='';if(matches.length<=0){return new RegExp(preg_quote(str),'g');} for(;i
|:\\'+(delimiter||'')+'-]','g'),'\\$&');}})(); bbcodeParser.addBBCode('[b]{TEXT}[/b]', '
{TEXT}
'); bbcodeParser.addBBCode('[u]{TEXT}[/u]', '
{TEXT}
'); bbcodeParser.addBBCode('[i]{TEXT}[/i]', '
{TEXT}
'); bbcodeParser.addBBCode('[url]{URL}[/url]', '
{URL}
'); bbcodeParser.addBBCode('[url={URL}]{TEXT}[/url]', '
{TEXT}
'); bbcodeParser.addBBCode(':)', '
'); bbcodeParser.addBBCode(':(', '
'); bbcodeParser.addBBCode(':P', '
'); bbcodeParser.addBBCode(':D', '
'); bbcodeParser.addBBCode(':S', '
'); bbcodeParser.addBBCode(':O', '
'); bbcodeParser.addBBCode(':=)', '
'); bbcodeParser.addBBCode(':|H', '
'); bbcodeParser.addBBCode(':X', '
'); bbcodeParser.addBBCode(':-*', '
'); /** Functions for Ajax **/ // Start AJAX // Variables for positioning scrollbar var scrol0 = -1; var i_scrol = 0; var mypostrequest = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); // Create the object for AJAX function ajaxF(file, parameters) { var ajxsend = 1; // parameter to check sending (Ajax busy) parameters += '&chatroom='+chatroom; // Add the "chatroom" // Sends data mypostrequest.open("POST", file, true); mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); mypostrequest.send(parameters); mypostrequest.onreadystatechange = stateChanged; // Function to display response function stateChanged() { var niv_scroll = document.getElementById('chats').scrollTop; // determine where the scrollbar is positioned if (mypostrequest.readyState==4) { if (mypostrequest.status==200 && document.getElementById('chats')) { // get chat content to be added in page. var objChat = JSON.parse(mypostrequest.responseText); setHtmlChat(objChat); // set and add chat content in page // Make auto-scroll to scrollbar position if it was moved, or bottom of DIV #chats var div = document.getElementById('chats'); var scrollHeight = Math.max(div.scrollHeight, div.clientHeight); if (niv_scroll!=0 && niv_scroll
with each chat line data if(nrchats > 0 && objChat.chats[0].chat != '') { for(var i=0; i
• '+ objChat.chats[i].user +' -
'+ objChat.chats[i].date +'
- '+ bbcodeParser.bbcodeToHtml(objChat.chats[i].chat) +'
'; } } else chatrows += '
'+ texts.notchat +'
'; if(document.getElementById('chats')) document.getElementById('chats').innerHTML = chatrows; // update tet chat } // refreshes online user list every seccond access if((refresh_usrs % 2) == 0) { // adds the users from object in array, and sorts them alphabetically var users = []; var user = document.getElementById('chatuser').value; if(chatuserset == 1) users.push(user); for(var kusr in objChat.users) { if(user != objChat.users[kusr]) users.push(objChat.users[kusr]); } // if the $users has items, add them in UL lists, else, return without UL if(users.length > 0) { users.sort(function(a, b) { var textA = a.toUpperCase(); var textB = b.toUpperCase(); return (textA < textB) ? -1 : (textA > textB) ? 1 : 0; }); chatusers += '
'+ users.join('
') +'
'; } else chatusers = texts.no1online; // if "logoutchat" is 1, removes the user from Online list if(logoutchat === 1) { var linethisuser = new RegExp('\
'+document.getElementById('chatuser').value+'\
([^\<]*)\<\/span\>\<\/li\>', 'i'); if(chatusers.match(linethisuser)) chatusers = chatusers.replace(linethisuser, ''); } if(document.getElementById('chatusers')) document.getElementById('chatusers').innerHTML = '
'+ texts.online +'
'+ chatusers; // update chat users } refresh_usrs++; } // Calls Ajax function to each 2 seconds (with chatuser) to function apelAjax() { callphp -= 1.5; // decrement callphp 1.5 seconds // sets file to access according to "sec", if it`s 0, accesses "setchat", else, the TXT file with chatroom name if(callphp <= 0) { callphp = 2.8 + (getNrChatUsers() * 0.3); // sets to call "setchat" according to number of online users var chatfile = setchat; } else var chatfile = getchat(); if(callphp > 10) callphp = 10 var chatusr = (chatuserset==1) ? (document.getElementById('chatuser').value) : ''; // if Ajax free, sends data, else, set free for next auto-call if(ajxsend === 0) ajaxF(chatfile, 'chatuser='+chatusr); else ajxsend = 0; setTimeout('apelAjax()', 1900); } apelAjax(); // Calls Ajax function