From: Lo?c C. <lo...@us...> - 2001-04-20 19:54:17
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/index_libs In directory usw-pr-cvs1:/tmp/cvs-serv9323/chat/lib/index_libs Modified Files: misc.lib.js do_enter_js_work.lib.php3 Added Files: msg_validation.lib.js Log Message: Improved javascript brief validation of messages and commands --- NEW FILE --- // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html | // +--------------------------------------------------------------------------+ // | Set of functions used to briefly validate a submission of the 'message' | // | box. | // | | // | This library is called by the 'chat/lib/index_libs/main_index.lib.php3' | // | script. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <te...@ph...> | // +--------------------------------------------------------------------------+ // // $Id: msg_validation.lib.js,v 1.1 2001/04/20 19:54:13 loic1 Exp $ // // Set of JavaScript functions used to validate messages. // var validCmds = new Array; validCmds[0] = /^\/!$/; validCmds[1] = /^\/announce (.+)$/i; validCmds[2] = /^\/ban (\* )?(.{1,30})$/i; validCmds[3] = /^\/clear$/i; validCmds[4] = /^\/(help|\?)$/i; validCmds[5] = /^\/ignore( -)?( (.+))?$/i; validCmds[6] = /^\/img$/i; validCmds[7] = /^\/invite( (.+))+$/i; validCmds[8] = /^\/join ((0|1) )?#(.{1,30})$/i; validCmds[9] = /^\/kick (.{1,30})$/i; validCmds[10] = /^\/me (.+)$/i; validCmds[11] = /^\/(msg|to) ([^ ]{1,30}) (.+)$/i; validCmds[12] = /^\/notify$/i; validCmds[13] = /^\/order$/i; validCmds[14] = /^\/profile$/i; validCmds[15] = /^\/promote (.{1,30})$/i; validCmds[16] = /^\/(quit|exit|bye)( (.+))?$/i; validCmds[17] = /^\/refresh( ([0-9]*))?$/i; validCmds[18] = /^\/save( ([0-9]*))?$/i; validCmds[19] = /^\/(show|last)( ([0-9]+))?$/i; validCmds[20] = /^\/timestamp$/i; validCmds[21] = /^\/whois (.{1,30})$/i; /** * Check whether the message looks like a valid command or not * * @param string the message * @return boolean whether the message looks like a command or not * * @access public */ function pmcIsValidCommand(theMessage) { for (i = 0; i < validCmds.length; i++) { if (validCmds[i].test(theMessage)) return true; } return false; } // end of the pmcIsCommand /** * Brief validation of the message or the command submitted by the 'input' * frame * * @param string error message to display in case of an invalid command * @return boolean whether the message or command should be submitted or not * * @access public */ function pmcValidateInputForm(invalidCmdMsg) { var msgBox = pmcGetInputForm('message'); // The replace function (js1.2) isn't supported -> no js tests are done if (typeof(msgBox.value.replace) == 'undefined') return true; // Submission looks like a command? var isCmd = (msgBox.value.substring(0,1) == '/'); // RegExp for some perticular command var reHist = /^\/!$/; var reHelp = /^\/(\?|help)$/i; // Ensure the message box isn't empty if (msgBox.value.replace(/ /g, '') == '') { msgBox.focus(); return false; } // It looks like a command but's not a valid one -> display error message else if (isCmd && !pmcIsValidCommand(msgBox.value)) { msgBox.select(); alert(jsInvalidCommandMsg); return false; } // It's the history command -> do the work else if (isCmd && reHist.test(msgBox.value)) { var prevMsg = pmcGetInputForm('prevMessage'); if (prevMsg.value == '') alert(jsInvalidCommandMsg); else msgBox.value = prevMsg.value; return false; } // It's the help command -> do the work else if (isCmd && reHelp.test(msgBox.value)) { var prevMsg = pmcGetInputForm('prevMessage'); prevMsg.value = msgBox.value; msgBox.value = ''; var pos = (jsCharset == 'windows-1256') ? 610 : 10; window.parent.pmcHelpPopup(pos); return false; } // It doesn't look like a command -> it's a message, then ensure a message // isn't currently being submitted... else if (!isCmd && jsInputForm.elements['sent'].value == 1) { msgBox.focus(); return false; } // ... and that the same message hasn't been submitted the last time else if (!isCmd && msgBox.value == jsInputForm.elements['prevMessage'].value) { msgBox.value = ''; msgBox.focus(); return false; } // All the tests have been succesfully passed -> submit the from else { jsInputForm.elements['sent'].value = 1; if (typeof(jsInputForm.elements['submitType'].disabled) != 'undefined') jsInputForm.elements['submitType'].disabled = true; return true; } } // end of the function 'pmcValidateInputForm()' Index: misc.lib.js =================================================================== RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/index_libs/misc.lib.js,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** misc.lib.js 2001/04/19 21:05:04 1.10 --- misc.lib.js 2001/04/20 19:54:13 1.11 *************** *** 155,230 **** /** - * Brief validation of the message or the command submitted by the 'input' - * frame - * - * @param string error message to display in case of an invalid command - * @return boolean whether the message or command should be submitted or not - * - * @access public - */ - function pmcValidateInputForm(invalidCmdMsg) - { - var msgBox = pmcGetInputForm('message'); - - // The replace function (js1.2) isn't supported -> no js tests are done - if (typeof(msgBox.value.replace) == 'undefined') - return true; - - // Submission looks like a command? - var isCmd = (msgBox.value.substring(0,1) == '/'); - // RegExp used to validate commands - var re = /^\/(!$|announce .+|ban .+|clear$|help$|\?$|ignore|img$|invite .+|join .+|kick .+|me .+|msg .+|to .+|notify$|order$|profile$|promote .+|quit|exit|bye|refresh|save|show|last|timestamp$|whois .+)/i; - // RegExp for the history command - var reHist = /^\/!$/; - - // Ensure the message box isn't empty - if (msgBox.value.replace(/ /g, '') == '') - { - msgBox.focus(); - return false; - } - // It looks like a command but's not a valid one -> display error message - else if (isCmd && !re.test(msgBox.value)) - { - msgBox.select(); - alert(jsInvalidCommandMsg); - return false; - } - // It's the history command -> do the work - else if (isCmd && reHist.test(msgBox.value)) - { - var prevMsg = pmcGetInputForm('prevMessage'); - if (prevMsg.value == '') - alert(jsInvalidCommandMsg); - else - msgBox.value = prevMsg.value; - return false; - } - // It doesn't look like a command -> it's a message, then ensure a message - // isn't currently being submitted... - else if (!isCmd && jsInputForm.elements['sent'].value == 1) - { - msgBox.focus(); - return false; - } - // ... and that the same message hasn't been submitted the last time - else if (!isCmd && msgBox.value == jsInputForm.elements['prevMessage'].value) - { - msgBox.value = ''; - msgBox.focus(); - return false; - } - // All the tests have been succesfully passed -> submit the from - else - { - jsInputForm.elements['sent'].value = 1; - if (typeof(jsInputForm.elements['submitType'].disabled) != 'undefined') - jsInputForm.elements['submitType'].disabled = true; - return true; - } - } // end of the function 'pmcValidateInputForm()' - - - /** * Launches the users popup according to the DHTML capacities of the browser * --- 155,158 ---- Index: do_enter_js_work.lib.php3 =================================================================== RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/index_libs/do_enter_js_work.lib.php3,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** do_enter_js_work.lib.php3 2001/04/19 21:05:04 1.5 --- do_enter_js_work.lib.php3 2001/04/20 19:54:13 1.6 *************** *** 46,49 **** --- 46,50 ---- var jsUrlQueryForHelp = '<?php echo('lang=' . $dbSessionVars['lang'] . $pmcQueryArgSeparator . 'jsVersion=' . $jsVersion); ?>'; var jsInvalidCommandMsg = '<?php echo(pmcSlashSingleQuotes(L_BAD_CMD)); ?>'; + var jsCharset = '<?php echo(L_CHARSET); ?>'; // --> </script> *************** *** 93,96 **** --- 94,100 ---- <!-- Gets the library that allows to launch the help popup --> <script src="<?php echo(_CHAT_PATH); ?>lib/index_libs/help_popup.lib.js" type="text/javascript" language="javascript"></script> + + <!-- Gets the library that allows to briefly validate commands and messages --> + <script src="<?php echo(_CHAT_PATH); ?>lib/index_libs/msg_validation.lib.js" type="text/javascript" language="javascript1.2"></script> |