From: Lo?c C. <lo...@us...> - 2001-04-10 15:03:38
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib In directory usw-pr-cvs1:/tmp/cvs-serv14790/chat/lib Modified Files: smilies.lib.php3 Log Message: Rewritten according to codding conventions Index: smilies.lib.php3 =================================================================== RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/smilies.lib.php3,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** smilies.lib.php3 2001/04/03 20:15:39 1.1 --- smilies.lib.php3 2001/04/10 15:03:35 1.2 *************** *** 1,16 **** <? ! /* ------------------------------------------------------------------ ! This library allows to transform text codes to graphical smilies. ! It is called by 'chat/input.php3'. ! ------------------------------------------------------------------ */ - // The table below define smilies code and associated gif names, width and height. - // You can add your own collection of smilies inside but be aware that codes may - // need to be slashed in some way because they are used as POSIX 1003.2 regular - // expressions (see the Check4Smilies function below). Moreover these codes are - // case sensitives. ! $smilies = Array( ':\)' => array('smile1.gif', 15, 15), ':D' => array('smile2.gif', 15, 15), --- 1,37 ---- <? ! // ! // +--------------------------------------------------------------------------+ ! // | phpMyChat version 0.15.0 | ! // +--------------------------------------------------------------------------+ ! // | Copyright (c) 2000-2001 The phpHeaven-team | ! // +--------------------------------------------------------------------------+ ! // | This library allows to transform some text codes to graphical smilies. | ! // | | ! // | It is called by the tutorials, the 'chat/help_popup.php3' script and all | ! // | the scripts that put messages in the database (main 'input' scripts and | ! // | some of the commands). | ! // +--------------------------------------------------------------------------+ ! // | From the phpMyChat project: | ! // | http://www.phpheaven.net/projects/phpMyChat/ | ! // | | ! // | Authors: the phpHeaven-team <php...@ya...> | ! // +--------------------------------------------------------------------------+ ! // ! // $Id$ ! // ! // Transform some text codes to graphical smilies. ! // ! /** ! * The table below define smilies' codes and associated gif names, width and ! * height. ! * You may add your own collection of smilies inside but be aware that codes ! * may need to be slashed in some way because they are used as POSIX 1003.2 ! * regular expression (see the 'checkForSmilies()' function below). ! * Moreover these codes are case sensitive. ! */ ! $smilies = array( ':\)' => array('smile1.gif', 15, 15), ':D' => array('smile2.gif', 15, 15), *************** *** 24,44 **** ); ! $maxWidth = 50; // Set the maximum width among similes ! $maxHeight = 15; // Set the maximum height among similes // ---- DO NOT MODIFY BELOW ---- ! // Slashes ' and " characters ! function specialSlash(&$str) { ! return str_replace('"','"',str_replace('\'','\\\'',$str)); ! } ! // Replace smilies code by gif URLs in messages ! function checkForSmilies(&$string, &$table) { ! $tmp = split('<a href|</a>', ' ' . $string . ' '); ! $i = 0; for (reset($tmp); $substring = current($tmp); next($tmp)) --- 45,86 ---- ); ! /** ! * Set the maximum width and height among similes ! */ ! $maxWidth = 50; ! $maxHeight = 15; // ---- DO NOT MODIFY BELOW ---- ! /** ! * Slashes ' and " characters ! * ! * @param string the text code to be slashed ! * ! * @return string the slashed string ! * ! * @access private ! */ ! function specialSlash($str = '') { ! return str_replace('"', '"', str_replace('\'', '\\\'', $str)); ! } // end of the 'specialSlash()' function ! ! /** ! * Replace smilies code by gif URLs in messages ! * ! * @param string the original message ! * @param array the smilies array ! * ! * @return string the formatted string ! * ! * @access public ! */ ! function checkForSmilies(&$string, &$theSmilies) { ! $tmp = split('<a href|</a>', ' ' . $string . ' '); ! $i = 0; for (reset($tmp); $substring = current($tmp); next($tmp)) *************** *** 47,58 **** if($substring == ' ') { } // $substring is not an HTTP link -> do the work for smilies else if (($i % 2) == 0) { ! while (list($key, $prop) = each($table)) { $substring = ereg_replace($key, ' <img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] . '" alt="' . str_replace('"', '"', stripslashes($key)) . '" /> ', $substring); ! }; $tmp[$i] = $substring; } --- 89,101 ---- if($substring == ' ') { + // void } // $substring is not an HTTP link -> do the work for smilies else if (($i % 2) == 0) { ! while (list($key, $prop) = each($theSmilies)) { $substring = ereg_replace($key, ' <img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] . '" alt="' . str_replace('"', '"', stripslashes($key)) . '" /> ', $substring); ! } $tmp[$i] = $substring; } *************** *** 63,101 **** } $i++; ! }; $string = trim(join('', $tmp)); unset($tmp); ! } ! // Display smilies in the help popup and in the tutorials ! function displaySmilies(&$toDisplay, &$table, &$tableSize, $target) { global $maxWidth, $maxHeight; ! $i = 0; ! $str1 = ''; ! $str2 = ''; ! $perLines = floor(600 / $maxWidth); ! ! while(list($key, $prop) = each($table)) { $i++; if ($target == 'help') ! $str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><a href="#" onclick="smiley2Input(\'' . specialSlash($key) . '\'); return false;"><img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] .'" border="0" alt="' . str_replace('"', '"', stripslashes($key)) . '" /></a></td>' . "\n"; else ! $str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] .'" border="0" alt="' . str_replace('"', '"', stripslashes($key)) . '" /></td>' . "\n"; ! $str2 .= "\t\t" . '<td align="center" nowrap="nowrap">' . stripslashes($key) . '</td>' . "\n"; ! ! if (is_integer($i / $perLines) || $i == $tableSize) { ! $toDisplay[] = $str1; ! $toDisplay[] = $str2; ! $str1 = ''; ! $str2 = ''; ! }; ! }; ! }; ?> --- 106,159 ---- } $i++; ! } $string = trim(join('', $tmp)); unset($tmp); ! } // end of the 'checkForSmilies()' function ! ! /** ! * Display smilies in the help popup and in the tutorials ! * ! * @param array the list of smilies codes in HTML format ! * @param array the smilies array ! * @param integer the smilies number ! * @param string the script to put smilies code into ('help' or 'tutorial') ! * ! * @return string the formatted string ! * ! * @global integer the maximum width among similes ! * @global integer the maximum height among similes ! * ! * @access public ! */ ! function displaySmilies(&$toDisplay, &$theSmilies, &$theSmiliesCnt, $target) { global $maxWidth, $maxHeight; + + $i = 0; + $str1 = ''; + $str2 = ''; + $perLines = floor(600 / $maxWidth); ! while(list($key, $prop) = each($theSmilies)) { $i++; if ($target == 'help') ! $str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><a href="#" onclick="smiley2Input(\'' . specialSlash($key) . '\'); return false;"><img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] .'" border="0" alt="' . str_replace('"', '"', stripslashes($key)) . '" /></a></td>' . "\n"; else ! $str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] .'" border="0" alt="' . str_replace('"', '"', stripslashes($key)) . '" /></td>' . "\n"; ! $str2 .= "\t\t" . '<td align="center" nowrap="nowrap">' . stripslashes($key) . '</td>' . "\n"; ! ! if (is_integer($i / $perLines) || $i == $theSmiliesCnt) { ! $toDisplay[] = $str1; ! $toDisplay[] = $str2; ! $str1 = ''; ! $str2 = ''; ! } ! } ! } // end of the 'displaySmilies()' function ?> |