From: Lo?c C. <lo...@us...> - 2001-04-14 16:05:09
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib In directory usw-pr-cvs1:/tmp/cvs-serv28962/chat/lib Modified Files: swearing.lib.php3 smilies.lib.php3 db_sessions.lib.php3 common.lib.php3 Log Message: Optimization of control structures Index: swearing.lib.php3 =================================================================== RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/swearing.lib.php3,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** swearing.lib.php3 2001/04/10 17:51:00 1.4 --- swearing.lib.php3 2001/04/14 16:05:06 1.5 *************** *** 30,35 **** /** ! * Check for swearings and optionnaly replace them by another string of ! * characters. * * You can add all the swearings you want in the '$swearings' array below. As --- 30,34 ---- /** ! * Define the list of swear words that should be avoided * * You can add all the swearings you want in the '$swearings' array below. As *************** *** 40,43 **** --- 39,66 ---- * as accentued ones. * + * This variable is declared inside the '$GLOBALS' array to ensure its scope is + * global (this library can be called from inside a function) + */ + $GLOBALS['swearings'] = array ( + 'shit', + 'fuck([[:alpha:]]*)' + ); + + /** + * Define the string that will be used to replace swear words + * + * This variable is declared inside the '$GLOBALS' array to ensure its scope is + * global (this library can be called from inside a function) + */ + $GLOBALS['replaceBy'] = '@#$*!'; + + + //--- Don't modify lines below --- + + + /** + * Check for swearings and optionnaly replace them by another string of + * characters. + * * @param string the string to search into * @param boolean whether to check only (1) or to check and replace swearings *************** *** 47,67 **** * value is 1, the cleaned string else * * @access public */ ! function checkWords($str = '', $testOnly = 0) { ! $swearings = array ( 'shit', ! 'fuck([[:alpha:]]*)' ! ); ! ! $replaceBy = '@#$*!'; // String that will replace swearings ! ! ! //--- Don't modify lines below --- ! $found = false; ! for (reset($swearings); $toFind = current($swearings); next($swearings)) { ! $found = eregi($toFind, $str); if ($found) { --- 70,89 ---- * value is 1, the cleaned string else * + * @global array the list of swear words that should be avoided + * @global string the string that will be used to replace swear words + * * @access public */ ! function checkWords($str = '', $testOnly = false) { ! global $swearings; ! global $replaceBy; ! $found = false; ! $swearingsCnt = count($swearings); ! reset($swearings); ! for ($i = 0; $i < $swearingsCnt; $i++) { ! $found = eregi($swearings[$i], $str); if ($found) { *************** *** 69,77 **** break; else ! $str = eregi_replace($toFind, $replaceBy, $str); } } - unset($swearings); return ($testOnly) ? $found : $str; } // end of the 'checkWords()' function --- 91,98 ---- break; else ! $str = eregi_replace($swearings[$i], $replaceBy, $str); } } return ($testOnly) ? $found : $str; } // end of the 'checkWords()' function Index: smilies.lib.php3 =================================================================== RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/smilies.lib.php3,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** smilies.lib.php3 2001/04/11 23:06:14 1.3 --- smilies.lib.php3 2001/04/14 16:05:06 1.4 *************** *** 86,95 **** $tmp = split('<a href|</a>', ' ' . $string . ' '); ! $i = 0; ! ! for (reset($tmp); $substring = current($tmp); next($tmp)) { // $substring is one of the trailing spaces added above -> do nothing ! if($substring == ' ') { // void --- 86,97 ---- $tmp = split('<a href|</a>', ' ' . $string . ' '); ! $arrayCnt = count($tmp); ! reset($tmp); ! for ($i = 0; $i < $arrayCnt; $i++) { + $substring = $tmp[$i]; + // $substring is one of the trailing spaces added above -> do nothing ! if ($substring == ' ') { // void *************** *** 109,113 **** $tmp[$i] = '<a href' . $substring . '</a>'; } - $i++; } $string = trim(join('', $tmp)); --- 111,114 ---- Index: db_sessions.lib.php3 =================================================================== RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/db_sessions.lib.php3,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** db_sessions.lib.php3 2001/04/13 10:29:19 1.5 --- db_sessions.lib.php3 2001/04/14 16:05:06 1.6 *************** *** 164,180 **** $i = 0; ! for (reset($tmp); $currenElt = current($tmp); next($tmp)) { if ($i % 2 == 0) // The name of a variable { ! $varName = substr($currenElt, strpos($currenElt, "\"") + 1, - 1); } else // the value of a variable { ! if (strpos($currenElt, "\"")) // Value is a string ! $varValue = substr($currenElt, strpos($currenElt, "\"") + 1, - 1); else // Value is an integer ! $varValue = $currenElt; ! if ($i == count($tmp) - 1) // Removes ending characters $varValue = ereg_replace('("|;)$', '', $varValue); --- 164,182 ---- $i = 0; ! $tmpCnt = count($tmp); ! reset($tmp); ! for ($k = 0; $k < $tmpCnt; $k++) { if ($i % 2 == 0) // The name of a variable { ! $varName = substr($tmp[$k], strpos($tmp[$k], "\"") + 1, - 1); } else // the value of a variable { ! if (strpos($tmp[$k], "\"")) // Value is a string ! $varValue = substr($tmp[$k], strpos($tmp[$k], "\"") + 1, - 1); else // Value is an integer ! $varValue = $tmp[$k]; ! if ($i == $tmpCnt - 1) // Removes ending characters $varValue = ereg_replace('("|;)$', '', $varValue); *************** *** 185,188 **** --- 187,191 ---- } unset($tmp); + unset($tmpCnt); return $ret; *************** *** 204,211 **** */ function in_array($needle, &$haystack) ! { ! for ($i = 0; $i < count($haystack) && $haystack[$i] != $needle; $i++); ! return ($i != count($haystack)); } // end of the 'in_array()' function } // end of the PHP < 4.0 case --- 207,215 ---- */ function in_array($needle, &$haystack) ! { ! $haystackCnt = count($haystack); ! for ($i = 0; $i < $haystackCnt && $haystack[$i] != $needle; $i++); ! return ($i != $haystackCnt); } // end of the 'in_array()' function } // end of the PHP < 4.0 case Index: common.lib.php3 =================================================================== RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/common.lib.php3,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** common.lib.php3 2001/04/13 08:59:26 1.4 --- common.lib.php3 2001/04/14 16:05:06 1.5 *************** *** 146,153 **** { $ret = 0; reset($which); ! while (list($key, $value) = each($which)) { ! $ret += pmcGrabGlobals($value); } return $ret; --- 146,154 ---- { $ret = 0; + $max = count($which); reset($which); ! for ($i = 0; $i < $max; $i++) { ! $ret += pmcGrabGlobals($which[$i]); } return $ret; |