From: Lo?c C. <lo...@us...> - 2001-04-03 20:15:43
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib In directory usw-pr-cvs1:/tmp/cvs-serv5636/chat/lib Added Files: smilies.lib.php3 Log Message: The first dev. version that works! Still many things to do, of course... --- NEW FILE --- <? /* ------------------------------------------------------------------ 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), ':o' => array('smile3.gif', 15, 15), ':\(' => array('smile4.gif', 15, 15), ';\)' => array('smile5.gif', 15, 15), ':p' => array('smile6.gif', 15, 15), '8\)' => array('smile7.gif', 15, 15), ':\[' => array('smile8.gif', 15, 15), ':kill:' => array('smile9.gif', 50, 15) ); $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)) { // $substring is one of the trailing spaces added above -> do nothing 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; } // $substring is an HTTP link -> just restore HTML tags for links else { $tmp[$i] = '<a href' . $substring . '</a>'; } $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 = ''; }; }; }; ?> |