|
From: Lo?c C. <lo...@us...> - 2001-04-24 10:57:26
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib
In directory usw-pr-cvs1:/tmp/cvs-serv4057/lib
Modified Files:
smilies.lib.php3
Log Message:
A really improved (and simplificated for the user) handdling smilies work
Index: smilies.lib.php3
===================================================================
RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/smilies.lib.php3,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** smilies.lib.php3 2001/04/19 21:05:04 1.6
--- smilies.lib.php3 2001/04/24 10:57:22 1.7
***************
*** 30,48 ****
* 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),
':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)
);
--- 30,55 ----
* 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 the
! * single quote and the backslash characters must be backslashed.
* Moreover these codes are case sensitive.
*/
$smilies = array(
! ':)' => array('smile1.gif', 15, 15),
':D' => array('smile2.gif', 15, 15),
':o' => array('smile3.gif', 15, 15),
! ':o)' => array('bignose.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),
! ':smoke:' => array('smoke.gif', 21, 15),
! ':bad:' => array('bad.gif', 15, 15),
! ':good:' => array('good.gif', 15, 15),
! ':coffee:' => array('coffee.gif', 16, 16),
! ':flower:' => array('flower.gif', 15, 15),
! ':my2cts:' => array('my2cents.gif', 15, 15),
! ':tux:' => array('tux.gif', 15, 15)
);
***************
*** 51,55 ****
*/
$maxWidth = 50;
! $maxHeight = 15;
--- 58,62 ----
*/
$maxWidth = 50;
! $maxHeight = 16;
***************
*** 57,62 ****
/**
! * Slashes ' and " characters
*
* @param string the text code to be slashed
*
--- 64,100 ----
/**
! * Special sorting function for the smilies array
*
+ * @param array a smiley text code
+ * @param array a smiley text code
+ *
+ * @return integer a value representing whether $a should be before $b in the
+ * sorted array or not
+ *
+ * @access private
+ */
+ function pmcSmiliesCmp($a, $b)
+ {
+ // same value or no overlapping -> no perticular sort order
+ if ($a == $b
+ || (strpos(' ' . $a, $b) == 0 && strpos(' ' . $b, $a) == 0))
+ {
+ return 0;
+ }
+ // between $a and $b, the first to search for must be the one included in
+ // the other (if $b is in $a -> $a must be detected first)
+ else
+ {
+ return (strpos(' ' . $a, $b) > 0) ? - 1 : 1;
+ }
+ } // end of the 'pmcSmiliesCmp()' function
+
+
+
+
+ /**
+ * Slashes ' and \ characters after the " character has been tranformed to its
+ * html entity
+ *
* @param string the text code to be slashed
*
***************
*** 67,71 ****
function specialSlash($str = '')
{
! return str_replace('"', '"', str_replace('\'', '\\\'', $str));
} // end of the 'specialSlash()' function
--- 105,109 ----
function specialSlash($str = '')
{
! return addslashes(str_replace('"', '"', $str));
} // end of the 'specialSlash()' function
***************
*** 87,90 ****
--- 125,132 ----
global $smilies;
+ // Sort the smilies array in a convenient order
+ reset($smilies);
+ uksort($smilies, 'pmcSmiliesCmp');
+
$tmp = split('<a href|</a>', ' ' . $string . ' ');
$arrayCnt = count($tmp);
***************
*** 102,110 ****
else if (($i % 2) == 0)
{
while (list($key, $prop) = each($smilies))
{
! $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
--- 144,161 ----
else if (($i % 2) == 0)
{
+ // trick for smilies at the beginning or the end of the string
+ $substring = ' ' . $substring . ' ';
+ reset($smilies);
while (list($key, $prop) = each($smilies))
{
! $substring = str_replace(' ' . $key . ' ', ' <img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] . '" alt="' . str_replace('"', '"', stripslashes($key)) . '" /> ', $substring);
! // '<' and '>' characters may have been converted to html entities
! if (strpos(' ' . $key, '>') + strpos(' ' . $key, '<') > 0)
! {
! $modifiedKey = str_replace('>', '>', str_replace('<', '<', $key));
! $substring = str_replace(' ' . $modifiedKey . ' ', ' <img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] . '" alt="' . str_replace('"', '"', stripslashes($key)) . '" /> ', $substring);
! }
}
! $tmp[$i] = substr($substring, 1, strlen($substring) - 2);
}
// $substring is an HTTP link -> just restore HTML tags for links
***************
*** 149,157 ****
if ($target == 'help')
! $str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><a href="#" onclick="pmcSmiley2Input(\'' . 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 == $smilCnt)
--- 200,208 ----
if ($target == 'help')
! $str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><a href="#" onclick="pmcSmiley2Input(\'' . specialSlash($key) . '\'); return false"><img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] .'" border="0" alt="' . str_replace('"', '"', $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('"', '"', $key) . '" /></td>' . "\n";
! $str2 .= "\t\t" . '<td align="center" nowrap="nowrap">' . $key . '</td>' . "\n";
if (is_integer($i / $perLines) || $i == $smilCnt)
|