diff --git a/README b/README index aa8948f..1761b63 100644 --- a/README +++ b/README @@ -18,7 +18,7 @@ along with this program. If not, see . GENERAL INFORMATION: -This is a PHP Chat based on LE CHAT v.1.14 . An up-to-date copy of this script can be downloaded at http://github.com/DanWin/le-chat-php +This is a PHP Chat based on LE CHAT v.1.14 . An up-to-date copy of this script can be downloaded at https://github.com/DanWin/le-chat-php The original perl LE CHAT script by Lucky Eddie can be downloaded at http://4fvfamdpoulu2nms.onion/lechat/ or via a tor2web proxy like https://4fvfamdpoulu2nms.tor2web.blutmagie.de/lechat/ if you don't have TOR installed. If you add your own cool features or have a feature request, please tell me and I will add them, if I like them. Please also let me know about any bugs you find in the code, so I can fix them. @@ -71,6 +71,19 @@ When you are done, you have to edit the chat script, to include your translation to the $L array in the load_lang() function at the bottom, similar to what I did for the German translation. Please share your translation with me, so I can add it to the official version. +REGEX: + +Yes, the chat supports regular expression filtering of messages. As regex tends to be difficult for most people, I decided to give it an extra section here. +Regex is very powerfull and can be used to filter messages that contain certain expressions and replace them with something else. +It can be used e.g. to turn BB Code into html, so it is possible to use BB Code in the chat to format messages. +To do this, use this Regex-Match '\[(u|b)\](.*?)\[\/\1\]' and this Regex-Replace '<$1>$2' and your text will be '[b]bold[/b]' or '[u]underlined[/u]'. +You can also use smileys by using this Regex-Match '(?-i::(cry|eek|lol|sad|smile|surprised|wink):)' and this Regex-Replace ':$1:' +And now if you enter ':smile:' an image with the smiley will be loaded from your server at '/pictures/smile.gif'. +The following should be escaped by putting '\' in front of it, if you are trying to match one of these characters '/ \ ^ . $ | ( ) [ ] * + ? { } ,'. +I used '/' as delimiter, so you will have to escape that, too. The only options I used is 'i' to make the regex case insensitive. +If you want to test your regex, before applying you can use this site and enter your Regex and Replacement there and click on preg_replace: http://www.phpliveregex.com/ +If you never used regex before, check out this starting guide to begin with regular expressions: http://docs.activestate.com/komodo/4.4/regex-intro.html + LIVE DEMO: If you want to see the script in action, you can visit my TOR hidden site http://tt3j2x4k5ycaa5zt.onion/chat.php or via a tor2web proxy like http://tt3j2x4k5ycaa5zt.tor2web.blutmagie.de/chat.php if you don't have TOR installed. diff --git a/README.md b/README.md index 9d365ee..e472854 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ General Information: -------------------- -This is a PHP Chat based on LE CHAT v.1.14 . An up-to-date copy of this script can be downloaded at http://github.com/DanWin/le-chat-php +This is a PHP Chat based on LE CHAT v.1.14 . An up-to-date copy of this script can be downloaded at https://github.com/DanWin/le-chat-php The original perl LE CHAT script by Lucky Eddie can be downloaded at [his site](http://4fvfamdpoulu2nms.onion/lechat/) or via a tor2web proxy like [this one](https://4fvfamdpoulu2nms.tor2web.blutmagie.de/lechat/) if you don't have TOR installed. If you add your own cool features or have a feature request, please tell me and I will add them, if I like them. Please also let me know about any bugs you find in the code, so I can fix them. @@ -57,6 +57,20 @@ When you are done, you have to edit the chat script, to include your translation to the $L array in the load_lang() function at the bottom, similar to what I did for the German translation. Please share your translation with me, so I can add it to the official version. +Regex: +------ + +Yes, the chat supports regular expression filtering of messages. As regex tends to be difficult for most people, I decided to give it an extra section here. +Regex is very powerfull and can be used to filter messages that contain certain expressions and replace them with something else. +It can be used e.g. to turn BB Code into html, so it is possible to use BB Code in the chat to format messages. +To do this, use this Regex-Match '\[(u|b)\](.*?)\[\/\1\]' and this Regex-Replace '<$1>$2' and your text will be '[b]bold[/b]' or '[u]underlined[/u]'. +You can also use smileys by using this Regex-Match '(?-i::(cry|eek|lol|sad|smile|surprised|wink):)' and this Regex-Replace ':$1:' +And now if you enter ':smile:' an image with the smiley will be loaded from your server at '/pictures/smile.gif'. +The following should be escaped by putting '\' in front of it, if you are trying to match one of these characters '/ \ ^ . $ | ( ) [ ] * + ? { } ,'. +I used '/' as delimiter, so you will have to escape that, too. The only options I used is 'i' to make the regex case insensitive. +If you want to test your regex, before applying you can use [this site](http://www.phpliveregex.com/) and enter your Regex and Replacement there and click on preg_replace. +If you never used regex before, check out [this starting guide](http://docs.activestate.com/komodo/4.4/regex-intro.html) to begin with regular expressions. + Live demo: ---------- diff --git a/chat.php b/chat.php index e7e7e66..183d7df 100755 --- a/chat.php +++ b/chat.php @@ -153,14 +153,13 @@ if(!isSet($_REQUEST['action'])){ if(in_array($tmp[0],$tables)) $num_tables++; } if($num_tables<7) send_init(); + update_db(); if(!valid_admin()) send_alogin(); if(!isSet($_REQUEST['do'])){ }elseif($_REQUEST['do']=='guestaccess'){ if(isSet($_REQUEST['set']) && preg_match('/^[0123]$/', $_REQUEST['set'])){ update_setting('guestaccess', $_REQUEST['set']); } - }elseif($_REQUEST['do']=='dbupdate'){ - update_db(); }elseif($_REQUEST['do']=='messages'){ update_messages(); } @@ -278,10 +277,6 @@ function send_setup(){ if($ga==0) echo " checked"; echo ">  ".submit($I['change']).""; thr(); - echo "
$I[dbupdate]"; - echo "<$H[form]>".hidden('action', 'setup').hidden('do', 'dbupdate').hidden('nick', $_REQUEST['nick']).hidden('pass', $_REQUEST['pass']).""; - echo '
 '.submit($I['update']).'
'; - thr(); echo "
$I[sysmessages]"; echo "<$H[form]>".hidden('action', 'setup').hidden('do', 'messages').hidden('nick', $_REQUEST['nick']).hidden('pass', $_REQUEST['pass']).""; echo "'; @@ -313,6 +308,14 @@ function send_init(){ print_end(); } +function send_update(){ + global $H, $I; + print_start(); + echo "

$I[dbupdate]


<$H[form]>".hidden('action', 'setup').submit($I['initgosetup']).'
'; + print_credits(); + print_end(); +} + function send_alogin(){ global $H, $I; print_start(); @@ -495,8 +498,8 @@ function send_filter($arg=''){ if($filter['regex']==0) $filter['match']=preg_replace('/(\\\\(.))/', "$2", $filter['match']); echo '
 $I[msgenter] 
'.frmadm('filter').hidden('id', $filter['id']); echo ""; - echo ""; - echo ""; + echo ""; + echo ""; echo ""; echo ""; echo ""; @@ -505,8 +508,8 @@ function send_filter($arg=''){ } echo '
$I[filter] $filter[id]:
'.frmadm('filter').hidden('id', '+'); echo ""; - echo ""; - echo ""; + echo ""; + echo ""; echo ""; echo ""; echo ""; @@ -592,7 +595,7 @@ function send_approve_waiting(){ }else{ echo "$I[waitempty]

"; } - print "$H[backtochat]"; + echo "$H[backtochat]"; print_end(); } @@ -666,11 +669,11 @@ function send_post(){ echo "
$I[newfilter]
"; if(!isSet($U['rejected'])) $U['rejected']=''; if(isSet($_REQUEST['multi']) && $_REQUEST['multi']=="on"){ - echo ""; + echo ""; }else{ - echo ""; + echo ""; } - echo ''; } - echo "'; $nowchatting=get_nowchatting(); @@ -1407,65 +1410,29 @@ function amend_profile(){ function save_profile(){ global $U, $C, $I, $mysqli; - if(isSet($_REQUEST['oldpass']) && $_REQUEST['oldpass']=='' && ($_REQUEST['newpass']!=='' || $_REQUEST['confirmpass']!=='')){ - send_profile($I['wrongpass']); - }elseif(isSet($_REQUEST['newpass']) && $_REQUEST['newpass']!==$_REQUEST['confirmpass']){ + if(!isSet($_REQUEST['oldpass'])) $_REQUEST['oldpass']=''; + if(!isSet($_REQUEST['newpass'])) $_REQUEST['newpass']=''; + if(!isSet($_REQUEST['confirmpass'])) $_REQUEST['confirmpass']=''; + if($_REQUEST['newpass']!==$_REQUEST['confirmpass']){ send_profile($I['noconfirm']); - } - // check and rewrite session - if(isSet($_REQUEST['oldpass']) && $_REQUEST['oldpass']!==''){ + }elseif($_REQUEST['newpass']!==''){ $U['oldhash']=md5(sha1(md5($U['nickname'].$_REQUEST['oldpass']))); - }else{ - $U['oldhash']=$U['passhash']; - } - if(isSet($_REQUEST['newpass']) && $_REQUEST['newpass']!==''){ $U['newhash']=md5(sha1(md5($U['nickname'].$_REQUEST['newpass']))); }else{ - $U['newhash']=$U['passhash']; + $U['oldhash']=$U['newhash']=$U['passhash']; } - $U['orihash']=$U['passhash']; - $stmt=mysqli_prepare($mysqli, 'SELECT * FROM `sessions` WHERE `session`=? AND `passhash`=?'); - mysqli_stmt_bind_param($stmt, 'ss', $U['session'], $U['oldhash']); + if($U['passhash']!==$U['oldhash']) send_profile($I['wrongpass']); + $U['passhash']=$U['newhash']; + amend_profile(); + $stmt=mysqli_prepare($mysqli, 'UPDATE `sessions` SET `refresh`=?, `displayname`=?, `fontinfo`=?, `style`=?, `passhash`=?, `boxwidth`=?, `boxheight`=?, `bgcolour`=?, `notesboxwidth`=?, `notesboxheight`=?, `timestamps`=?, `embed`=? WHERE `session`=?'); + mysqli_stmt_bind_param($stmt, 'dssssddsdddds', $U['refresh'], $U['displayname'], $U['fontinfo'], $U['style'], $U['passhash'], $U['boxwidth'], $U['boxheight'], $U['bgcolour'], $U['notesboxwidth'], $U['notesboxheight'], $U['timestamps'], $U['embed'], $U['session']); mysqli_stmt_execute($stmt); - mysqli_stmt_store_result($stmt); - if(mysqli_stmt_num_rows($stmt)>0){ - mysqli_stmt_free_result($stmt); - mysqli_stmt_close($stmt); - amend_profile(); - $U['passhash']=$U['newhash']; - $stmt=mysqli_prepare($mysqli, 'UPDATE `sessions` SET `refresh`=?, `displayname`=?, `fontinfo`=?, `style`=?, `passhash`=?, `boxwidth`=?, `boxheight`=?, `bgcolour`=?, `notesboxwidth`=?, `notesboxheight`=?, `timestamps`=?, `embed`=? WHERE `session`=?'); - mysqli_stmt_bind_param($stmt, 'dssssddsdddds', $U['refresh'], $U['displayname'], $U['fontinfo'], $U['style'], $U['passhash'], $U['boxwidth'], $U['boxheight'], $U['bgcolour'], $U['notesboxwidth'], $U['notesboxheight'], $U['timestamps'], $U['embed'], $U['session']); - mysqli_stmt_execute($stmt); - mysqli_stmt_close($stmt); - }else{ - mysqli_stmt_free_result($stmt); - mysqli_stmt_close($stmt); - } - if($U['orihash']!==$U['oldhash']) send_profile($I['wrongpass']); - // rewrite member file + mysqli_stmt_close($stmt); if($U['status']>=2){ - $err=''; - $stmt=mysqli_prepare($mysqli, 'SELECT `passhash`, `status` FROM `members` WHERE `nickname`=?'); - mysqli_stmt_bind_param($stmt, 's', $U['nickname']); + $stmt=mysqli_prepare($mysqli, 'UPDATE `members` SET `passhash`=?, `refresh`=?, `colour`=?, `bgcolour`=?, `fontface`=?, `fonttags`=?, `boxwidth`=?, `boxheight`=?, `notesboxwidth`=?, `notesboxheight`=?, `timestamps`=?, `embed`=? WHERE `nickname`=?'); + mysqli_stmt_bind_param($stmt, 'sdssssdddddds', $U['passhash'], $U['refresh'], $U['colour'], $U['bgcolour'], $U['fontface'], $U['fonttags'], $U['boxwidth'], $U['boxheight'], $U['notesboxwidth'], $U['notesboxheight'], $U['timestamps'], $U['embed'], $U['nickname']); mysqli_stmt_execute($stmt); - mysqli_stmt_bind_result($stmt, $temp['passhash'], $temp['status']); - if(mysqli_stmt_fetch($stmt)){ - mysqli_stmt_close($stmt); - $U['sessionstatus']=$U['status']; - $U['status']=$temp['status']; - if($temp['passhash']!==$U['orihash']){ - $err=$I['wrongpass']; - }else{ - $stmt=mysqli_prepare($mysqli, 'UPDATE `members` SET `passhash`=?, `refresh`=?, `colour`=?, `bgcolour`=?, `fontface`=?, `fonttags`=?, `boxwidth`=?, `boxheight`=?, `notesboxwidth`=?, `notesboxheight`=?, `timestamps`=?, `embed`=? WHERE `nickname`=?'); - mysqli_stmt_bind_param($stmt, 'sdssssdddddds', $U['passhash'], $U['refresh'], $U['colour'], $U['bgcolour'], $U['fontface'], $U['fonttags'], $U['boxwidth'], $U['boxheight'], $U['notesboxwidth'], $U['notesboxheight'], $U['timestamps'], $U['embed'], $U['nickname']); - mysqli_stmt_execute($stmt); - mysqli_stmt_close($stmt); - } - $U['status']=$U['sessionstatus']; - }else{ - mysqli_stmt_close($stmt); - } - if($err!=='') send_profile($err); + mysqli_stmt_close($stmt); } send_profile($I['succprofile']); } @@ -1554,6 +1521,7 @@ function validate_input(){ if($_REQUEST['sendto']==$chatter[0]){ $U['recipient']=$chatter[0]; $U['displayrecp']=style_this($chatter[0], $chatter[2]); + break; } } if($U['recipient']!==''){ @@ -1872,7 +1840,7 @@ function init_chat(){ while($tmp=mysqli_fetch_array($result, MYSQLI_NUM)){ if(in_array($tmp[0],$tables)) $num_tables++; } - if($num_tables==7){ + if($num_tables>=7){ $suwrite=$I['initdbexist']; $result=mysqli_query($mysqli, 'SELECT * FROM `members` WHERE `status`=\'8\''); if(mysqli_num_rows($result)>0){ @@ -1935,8 +1903,8 @@ function init_chat(){ $suwrite=$I['susuccess']; } print_start(); - print "

$I[init]


$I[sulogin]

$suwrite


"; - print "<$H[form]>".hidden('action', 'setup').hidden('nick', $_REQUEST['sunick']).hidden('pass', $_REQUEST['supass']).submit($I['initgosetup']).''; + echo "

$I[init]


$I[sulogin]

$suwrite


"; + echo "<$H[form]>".hidden('action', 'setup').hidden('nick', $_REQUEST['sunick']).hidden('pass', $_REQUEST['supass']).submit($I['initgosetup']).''; print_credits(); print_end(); } @@ -1946,6 +1914,7 @@ function update_db(){ $dbversion=get_setting('dbversion'); if($dbversion<$C['dbversion']){ update_setting('dbversion', $C['dbversion']); + send_update(); } } diff --git a/lang_de.php b/lang_de.php index ab57573..2485531 100644 --- a/lang_de.php +++ b/lang_de.php @@ -42,8 +42,7 @@ $I=array( 'initdbexist' => 'Datenbanktabellen existieren bereits! Um vortzufahren, musst du diese Tabellen zuerst manuell löschen.', 'initsuexist' => 'Ein Superadmin existiert bereits!', 'initgosetup' => 'Zur Einrichtungsseite gehen', - 'dbupdate' => 'Datenbank aktualisieren', - 'update' => 'Aktualisieren', + 'dbupdate' => 'Datenbank erfolgreich aktualisiert!', 'sysmessages' => 'Systemnachrichten', 'msgenter' => 'Eintritt', 'msgexit' => 'Verlassen', diff --git a/lang_en.php b/lang_en.php index 2600d4b..e123a0c 100644 --- a/lang_en.php +++ b/lang_en.php @@ -46,8 +46,7 @@ $I=array( 'nick' => 'Nickname:', 'pass' => 'Password:', 'login' => 'Login', - 'dbupdate' => 'Update database', - 'update' => 'Update', + 'dbupdate' => 'Database successfully updated!', 'sysmessages' => 'System messages', 'msgenter' => 'Entrance', 'msgexit' => 'Leaving',
$U[displayname]:'.submit($I['talkto'])."'.submit($I['talkto'])."
$I[choosecol]
$I[choosecol]